aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Checking.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/typer/Checking.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/typer/Checking.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Checking.scala9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/typer/Checking.scala b/src/dotty/tools/dotc/typer/Checking.scala
index 415cd5d6a..42eede5e9 100644
--- a/src/dotty/tools/dotc/typer/Checking.scala
+++ b/src/dotty/tools/dotc/typer/Checking.scala
@@ -344,6 +344,7 @@ object Checking {
fail(i"only classes can have declared but undefined members$varNote")
checkWithDeferred(Private)
checkWithDeferred(Final)
+ checkWithDeferred(Inline)
}
if (sym.isValueClass && sym.is(Trait) && !sym.isRefinementClass)
fail(i"$sym cannot extend AnyVal")
@@ -479,6 +480,13 @@ trait Checking {
tp
}
+ /** Check that `tree` is a pure expression of constant type */
+ def checkInlineConformant(tree: Tree, what: => String)(implicit ctx: Context): Unit =
+ tree.tpe.widenTermRefExpr match {
+ case tp: ConstantType if isPureExpr(tree) => // ok
+ case _ => ctx.error(em"$what must be a constant expression", tree.pos)
+ }
+
/** Check that class does not define same symbol twice */
def checkNoDoubleDefs(cls: Symbol)(implicit ctx: Context): Unit = {
val seen = new mutable.HashMap[Name, List[Symbol]] {
@@ -543,6 +551,7 @@ trait NoChecking extends Checking {
override def checkClassType(tp: Type, pos: Position, traitReq: Boolean, stablePrefixReq: Boolean)(implicit ctx: Context): Type = tp
override def checkImplicitParamsNotSingletons(vparamss: List[List[ValDef]])(implicit ctx: Context): Unit = ()
override def checkFeasible(tp: Type, pos: Position, where: => String = "")(implicit ctx: Context): Type = tp
+ override def checkInlineConformant(tree: Tree, what: => String)(implicit ctx: Context) = ()
override def checkNoDoubleDefs(cls: Symbol)(implicit ctx: Context): Unit = ()
override def checkParentCall(call: Tree, caller: ClassSymbol)(implicit ctx: Context) = ()
override def checkSimpleKinded(tpt: Tree)(implicit ctx: Context): Tree = tpt