Skip to content

Commit

Permalink
Merge pull request scala#1599 from dotty-staging/fix-#1570
Browse files Browse the repository at this point in the history
Fix scala#1570: Allow inline parameters as inline args
  • Loading branch information
smarter authored Oct 25, 2016
2 parents 0cd907d + 652cce0 commit f1284b4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/dotty/tools/dotc/core/Flags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,9 @@ object Flags {
/** An inline method */
final val InlineMethod = allOf(Inline, Method)

/** An inline parameter */
final val InlineParam = allOf(Inline, Param)

/** A parameter or parameter accessor */
final val ParamOrAccessor = Param | ParamAccessor

Expand Down
11 changes: 7 additions & 4 deletions src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,13 @@ trait Checking {

/** 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 tp if defn.isFunctionType(tp) && isPureExpr(tree) => // ok
case _ => ctx.error(em"$what must be a constant expression or a function", tree.pos)
tree.tpe match {
case tp: TermRef if tp.symbol.is(InlineParam) => // ok
case tp => tp.widenTermRefExpr match {
case tp: ConstantType if isPureExpr(tree) => // ok
case tp if defn.isFunctionType(tp) && isPureExpr(tree) => // ok
case _ => ctx.error(em"$what must be a constant expression or a function", tree.pos)
}
}

/** Check that class does not define same symbol twice */
Expand Down
4 changes: 4 additions & 0 deletions tests/pos/i1570.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object Test {
inline def foo(inline n: Int) = bar(n)
inline def bar(inline n: Int) = n
}

0 comments on commit f1284b4

Please sign in to comment.