Skip to content

Commit f1284b4

Browse files
authored
Merge pull request #1599 from dotty-staging/fix-#1570
Fix #1570: Allow inline parameters as inline args
2 parents 0cd907d + 652cce0 commit f1284b4

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/dotty/tools/dotc/core/Flags.scala

+3
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,9 @@ object Flags {
544544
/** An inline method */
545545
final val InlineMethod = allOf(Inline, Method)
546546

547+
/** An inline parameter */
548+
final val InlineParam = allOf(Inline, Param)
549+
547550
/** A parameter or parameter accessor */
548551
final val ParamOrAccessor = Param | ParamAccessor
549552

src/dotty/tools/dotc/typer/Checking.scala

+7-4
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,13 @@ trait Checking {
482482

483483
/** Check that `tree` is a pure expression of constant type */
484484
def checkInlineConformant(tree: Tree, what: => String)(implicit ctx: Context): Unit =
485-
tree.tpe.widenTermRefExpr match {
486-
case tp: ConstantType if isPureExpr(tree) => // ok
487-
case tp if defn.isFunctionType(tp) && isPureExpr(tree) => // ok
488-
case _ => ctx.error(em"$what must be a constant expression or a function", tree.pos)
485+
tree.tpe match {
486+
case tp: TermRef if tp.symbol.is(InlineParam) => // ok
487+
case tp => tp.widenTermRefExpr match {
488+
case tp: ConstantType if isPureExpr(tree) => // ok
489+
case tp if defn.isFunctionType(tp) && isPureExpr(tree) => // ok
490+
case _ => ctx.error(em"$what must be a constant expression or a function", tree.pos)
491+
}
489492
}
490493

491494
/** Check that class does not define same symbol twice */

tests/pos/i1570.scala

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object Test {
2+
inline def foo(inline n: Int) = bar(n)
3+
inline def bar(inline n: Int) = n
4+
}

0 commit comments

Comments
 (0)