aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/Types.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-09-12 13:01:28 +0200
committerMartin Odersky <odersky@gmail.com>2016-10-02 16:12:28 +0200
commit845b689a4a652fa79a7d0621f5ebe15bbf9225c7 (patch)
treece308233797b8b032b25c8ed29b6663da8742340 /src/dotty/tools/dotc/core/Types.scala
parentb559aff35d6d365284fc1e05a3ca49a17551df29 (diff)
downloaddotty-845b689a4a652fa79a7d0621f5ebe15bbf9225c7.tar.gz
dotty-845b689a4a652fa79a7d0621f5ebe15bbf9225c7.tar.bz2
dotty-845b689a4a652fa79a7d0621f5ebe15bbf9225c7.zip
Add inline for vals
- allow inline as an alternative to final for vals (final is retained for backwards compatibility for now) - allow inline for parameters - check that rhs of inline value has a constant type - check that arguments to inline value parameters have constant type - check that inline members are not deferred - make inline members effectively final
Diffstat (limited to 'src/dotty/tools/dotc/core/Types.scala')
-rw-r--r--src/dotty/tools/dotc/core/Types.scala15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index 0af673561..0c9a12701 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -2419,7 +2419,12 @@ object Types {
apply(nme.syntheticParamNames(paramTypes.length), paramTypes)(resultTypeExp)
def apply(paramTypes: List[Type], resultType: Type)(implicit ctx: Context): MethodType =
apply(nme.syntheticParamNames(paramTypes.length), paramTypes, resultType)
+
+ /** Produce method type from parameter symbols, with special mappings for repeated
+ * and inline parameters.
+ */
def fromSymbols(params: List[Symbol], resultType: Type)(implicit ctx: Context) = {
+ /** Replace @repeated annotations on Seq or Array types by <repeated> types */
def translateRepeated(tp: Type): Type = tp match {
case tp @ ExprType(tp1) => tp.derivedExprType(translateRepeated(tp1))
case AnnotatedType(tp, annot) if annot matches defn.RepeatedAnnot =>
@@ -2429,7 +2434,15 @@ object Types {
case tp =>
tp
}
- def paramInfo(param: Symbol): Type = translateRepeated(param.info)
+ /** Add @inlineParam to inline call-by-value parameters */
+ def translateInline(tp: Type): Type = tp match {
+ case tp @ ExprType(tp1) => tp
+ case _ => AnnotatedType(tp, Annotation(defn.InlineParamAnnot))
+ }
+ def paramInfo(param: Symbol): Type = {
+ val paramType = translateRepeated(param.info)
+ if (param.is(Inline)) translateInline(paramType) else paramType
+ }
def transformResult(mt: MethodType) =
resultType.subst(params, (0 until params.length).toList map (MethodParam(mt, _)))
apply(params map (_.name.asTermName), params map paramInfo)(transformResult _)