Skip to content

Commit d7c0574

Browse files
Merge pull request #8832 from dotty-staging/let-inline-vals-implement-abstract-inline-def-or-val
Let inline val implement abstract inline def/val
2 parents c5a76f0 + ee24482 commit d7c0574

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

compiler/src/dotty/tools/dotc/typer/RefChecks.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ object RefChecks {
398398
overrideError("is an extension method, cannot override a normal method")
399399
else if (other.isAllOf(ExtensionMethod) && !member.isAllOf(ExtensionMethod)) // (1.9.2)
400400
overrideError("is a normal method, cannot override an extension method")
401-
else if other.isInlineMethod && !member.isInlineMethod then // (1.10)
401+
else if other.is(Inline) && !member.is(Inline) then // (1.10)
402402
overrideError("is not inline, cannot implement an inline method")
403403
else if (other.isScala2Macro && !member.isScala2Macro) // (1.11)
404404
overrideError("cannot be used here - only Scala-2 macros can override Scala-2 macros")

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3082,18 +3082,17 @@ class Typer extends Namer
30823082
checkEqualityEvidence(tree, pt)
30833083
tree
30843084
}
3085+
else if (methPart(tree).symbol.isAllOf(Inline | Deferred) && !ctx.inInlineMethod) then
3086+
errorTree(tree, i"Deferred inline ${methPart(tree).symbol.showLocated} cannot be invoked")
30853087
else if (Inliner.isInlineable(tree) &&
30863088
!ctx.settings.YnoInline.value &&
30873089
!suppressInline) {
30883090
tree.tpe <:< wildApprox(pt)
30893091
val errorCount = ctx.reporter.errorCount
30903092
val meth = methPart(tree).symbol
3091-
if meth.is(Deferred) then
3092-
errorTree(tree, i"Deferred inline ${meth.showLocated} cannot be invoked")
3093-
else
3094-
val inlined = Inliner.inlineCall(tree)
3095-
if ((inlined ne tree) && errorCount == ctx.reporter.errorCount) readaptSimplified(inlined)
3096-
else inlined
3093+
val inlined = Inliner.inlineCall(tree)
3094+
if ((inlined ne tree) && errorCount == ctx.reporter.errorCount) readaptSimplified(inlined)
3095+
else inlined
30973096
}
30983097
else if (tree.symbol.isScala2Macro &&
30993098
// raw and s are eliminated by the StringInterpolatorOpt phase

tests/neg/abstract-inline-val.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
trait C:
2+
inline def x: Int
3+
inline val y: Int
4+
5+
def test: Unit =
6+
val c: C = ???
7+
c.x // error
8+
c.y // error

tests/pos/abstract-inline-val.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
trait C:
2+
inline def x: Int
3+
inline val y: Int
4+
5+
class C1 extends C:
6+
inline val x = 1
7+
inline val y = 2
8+
9+
class C2 extends C:
10+
inline def x = 3
11+
inline val y = 4

0 commit comments

Comments
 (0)