diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index 501a1bdbf16c..7e08fd2522ac 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -398,7 +398,7 @@ object RefChecks { overrideError("is an extension method, cannot override a normal method") else if (other.isAllOf(ExtensionMethod) && !member.isAllOf(ExtensionMethod)) // (1.9.2) overrideError("is a normal method, cannot override an extension method") - else if other.isInlineMethod && !member.isInlineMethod then // (1.10) + else if other.is(Inline) && !member.is(Inline) then // (1.10) overrideError("is not inline, cannot implement an inline method") else if (other.isScala2Macro && !member.isScala2Macro) // (1.11) overrideError("cannot be used here - only Scala-2 macros can override Scala-2 macros") diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 5ef55d44f0ed..9c4ba0b47128 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -3082,18 +3082,17 @@ class Typer extends Namer checkEqualityEvidence(tree, pt) tree } + else if (methPart(tree).symbol.isAllOf(Inline | Deferred) && !ctx.inInlineMethod) then + errorTree(tree, i"Deferred inline ${methPart(tree).symbol.showLocated} cannot be invoked") else if (Inliner.isInlineable(tree) && !ctx.settings.YnoInline.value && !suppressInline) { tree.tpe <:< wildApprox(pt) val errorCount = ctx.reporter.errorCount val meth = methPart(tree).symbol - if meth.is(Deferred) then - errorTree(tree, i"Deferred inline ${meth.showLocated} cannot be invoked") - else - val inlined = Inliner.inlineCall(tree) - if ((inlined ne tree) && errorCount == ctx.reporter.errorCount) readaptSimplified(inlined) - else inlined + val inlined = Inliner.inlineCall(tree) + if ((inlined ne tree) && errorCount == ctx.reporter.errorCount) readaptSimplified(inlined) + else inlined } else if (tree.symbol.isScala2Macro && // raw and s are eliminated by the StringInterpolatorOpt phase diff --git a/tests/neg/abstract-inline-val.scala b/tests/neg/abstract-inline-val.scala new file mode 100644 index 000000000000..1bcca078ad52 --- /dev/null +++ b/tests/neg/abstract-inline-val.scala @@ -0,0 +1,8 @@ +trait C: + inline def x: Int + inline val y: Int + +def test: Unit = + val c: C = ??? + c.x // error + c.y // error diff --git a/tests/pos/abstract-inline-val.scala b/tests/pos/abstract-inline-val.scala new file mode 100644 index 000000000000..6ea95eea5151 --- /dev/null +++ b/tests/pos/abstract-inline-val.scala @@ -0,0 +1,11 @@ +trait C: + inline def x: Int + inline val y: Int + +class C1 extends C: + inline val x = 1 + inline val y = 2 + +class C2 extends C: + inline def x = 3 + inline val y = 4