Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/inlines/Inlines.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ object Inlines:
def inInlineMethod(using Context): Boolean =
ctx.owner.ownersIterator.exists(_.isInlineMethod)

/** Are we in an inline val body? */
def inInlineVal(using Context): Boolean =
ctx.owner.ownersIterator.exists(_.isInlineVal)

/** Can a call to method `meth` be inlined? */
def isInlineable(meth: Symbol)(using Context): Boolean =
meth.is(Inline) && meth.hasAnnotation(defn.BodyAnnot) && !inInlineMethod
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/Inlining.scala
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Inlining extends MacroTransform, IdentityDenotTransformer {
new TreeTraverser {
def traverse(tree: Tree)(using Context): Unit =
tree match
case tree: RefTree if !Inlines.inInlineMethod && StagingLevel.level == 0 =>
case tree: RefTree if !(Inlines.inInlineMethod || Inlines.inInlineVal) && StagingLevel.level == 0 =>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could Inlines.inInlineMethodOrVal to reduce walking owners chain.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it is more natural and efficient to check symbol.isInlineMethod before the rest of the condition.

assert(!tree.symbol.isInlineMethod, tree.show)
case _ =>
traverseChildren(tree)
Expand Down
7 changes: 7 additions & 0 deletions tests/neg/i26215.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//> using options -Ycheck:all

object O1:
inline def x = 10

object O2:
inline val y = O1.x // error: inline value must have a literal constant type
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an improvement in the error message, since transparent inline def x is the required fix in the test code, for either the check or the subsequent error.

Loading