From 83b23e2cb0c2c79e18854635bcf4fdbf8c89625d Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 4 Dec 2019 17:44:57 +0100 Subject: [PATCH 1/5] Emit inline errors at expansion site --- .../dotc/reporting/MessageRendering.scala | 9 +++++---- .../dotty/tools/dotc/util/SourcePosition.scala | 11 +++++++++++ .../dotty/tools/vulpix/ParallelTesting.scala | 9 +++++---- .../neg-macros/macros-in-same-project-2.scala | 4 ++-- tests/neg/cannot-reduce-inline-match.check | 18 ++++++++---------- tests/neg/cannot-reduce-inline-match.scala | 4 ++-- tests/neg/cannot-reduce-summonFrom.scala | 4 ++-- tests/neg/i6371/A_1.scala | 2 +- tests/neg/i6371/B_2.scala | 2 +- tests/neg/inline-error-pos.check | 9 +++++++++ tests/neg/inline-error-pos.scala | 9 +++++++++ tests/neg/inlineAccess/C_1.scala | 2 +- tests/neg/inlineAccess/Test_2.scala | 2 +- tests/neg/summonFrom-ambiguous-bind.scala | 4 ++-- tests/neg/summonFrom-ambiguous.scala | 4 ++-- 15 files changed, 61 insertions(+), 32 deletions(-) create mode 100644 tests/neg/inline-error-pos.check create mode 100644 tests/neg/inline-error-pos.scala diff --git a/compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala b/compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala index e4e01de27e4d..48b22a8f4057 100644 --- a/compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala +++ b/compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala @@ -33,7 +33,7 @@ trait MessageRendering { */ def outer(pos: SourcePosition, prefix: String)(implicit ctx: Context): List[String] = if (pos.outer.exists) - i"$prefix| This location is in code that was inlined at ${pos.outer}" :: + i"$prefix| This location is in code that was inlined at $pos" :: outer(pos.outer, prefix) else Nil @@ -149,9 +149,10 @@ trait MessageRendering { val posString = posStr(pos, diagnosticLevel, msg) if (posString.nonEmpty) sb.append(posString).append(EOL) if (pos.exists && pos.source.file.exists) { - val (srcBefore, srcAfter, offset) = sourceLines(pos, diagnosticLevel) - val marker = columnMarker(pos, offset, diagnosticLevel) - val err = errorMsg(pos, msg.msg, offset) + val pos1 = pos.nonInlined + val (srcBefore, srcAfter, offset) = sourceLines(pos1, diagnosticLevel) + val marker = columnMarker(pos1, offset, diagnosticLevel) + val err = errorMsg(pos1, msg.msg, offset) sb.append((srcBefore ::: marker :: err :: outer(pos, " " * (offset - 1)) ::: srcAfter).mkString(EOL)) } else sb.append(msg.msg) diff --git a/compiler/src/dotty/tools/dotc/util/SourcePosition.scala b/compiler/src/dotty/tools/dotc/util/SourcePosition.scala index 62744659dde3..65acfa47dac2 100644 --- a/compiler/src/dotty/tools/dotc/util/SourcePosition.scala +++ b/compiler/src/dotty/tools/dotc/util/SourcePosition.scala @@ -64,6 +64,17 @@ extends interfaces.SourcePosition with Showable { def outermost: SourcePosition = if outer == null || outer == NoSourcePosition then this else outer.outermost + /** Inner most position that is contained within the `outermost` position. + * Most precise position that that comes from the call site. + */ + def nonInlined: SourcePosition = { + val om = outermost + def rec(self: SourcePosition): SourcePosition = + if outermost.contains(self) then self else rec(self.outer) + rec(this) + } + + override def toString: String = s"${if (source.exists) source.file.toString else "(no source)"}:$span" diff --git a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala index ad1a8bc868ea..f9284c642ab3 100644 --- a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala +++ b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala @@ -679,11 +679,12 @@ trait ParallelTesting extends RunnerOrchestration { self => } def getMissingExpectedErrors(errorMap: HashMap[String, Integer], reporterErrors: Iterator[MessageContainer]) = !reporterErrors.forall { error => - val key = if (error.pos.exists) { + val pos1 = error.pos.nonInlined + val key = if (pos1.exists) { def toRelative(path: String): String = // For some reason, absolute paths leak from the compiler itself... path.split("/").dropWhile(_ != "tests").mkString("/") - val fileName = toRelative(error.pos.source.file.toString) - s"$fileName:${error.pos.line}" + val fileName = toRelative(pos1.source.file.toString) + s"$fileName:${pos1.line}" } else "nopos" @@ -695,7 +696,7 @@ trait ParallelTesting extends RunnerOrchestration { self => true } else { - echo(s"Error reported in ${error.pos.source}, but no annotation found") + echo(s"Error reported in ${pos1.source}, but no annotation found") false } } diff --git a/tests/neg-macros/macros-in-same-project-2.scala b/tests/neg-macros/macros-in-same-project-2.scala index 0e4053dc1aa9..ca60fe4666ac 100644 --- a/tests/neg-macros/macros-in-same-project-2.scala +++ b/tests/neg-macros/macros-in-same-project-2.scala @@ -3,9 +3,9 @@ import scala.quoted._ object Bar { - myMacro() + myMacro() // error - inline def myMacro(): Unit = myMacro2() // error + inline def myMacro(): Unit = myMacro2() inline def myMacro2(): Unit = ${ aMacroImplementation } def aMacroImplementation(given QuoteContext): Expr[Unit] = '{} diff --git a/tests/neg/cannot-reduce-inline-match.check b/tests/neg/cannot-reduce-inline-match.check index adeab2fc97ee..deef3789ddf5 100644 --- a/tests/neg/cannot-reduce-inline-match.check +++ b/tests/neg/cannot-reduce-inline-match.check @@ -1,11 +1,9 @@ -- Error: tests/neg/cannot-reduce-inline-match.scala:3:13 -------------------------------------------------------------- -3 | inline x match { // error - | ^ - | cannot reduce inline match with - | scrutinee: { - | "f" - | } : String("f") - | patterns : case _:Int - | This location is in code that was inlined at cannot-reduce-inline-match.scala:9 -4 | case _: Int => -5 | } +9 | foo("f") // error + | ^^^^^^^^ + | cannot reduce inline match with + | scrutinee: { + | "f" + | } : String("f") + | patterns : case _:Int + | This location is in code that was inlined at cannot-reduce-inline-match.scala:3 diff --git a/tests/neg/cannot-reduce-inline-match.scala b/tests/neg/cannot-reduce-inline-match.scala index b9b0ad0d5dda..635a067ab5c4 100644 --- a/tests/neg/cannot-reduce-inline-match.scala +++ b/tests/neg/cannot-reduce-inline-match.scala @@ -1,11 +1,11 @@ object Test { inline def foo[T](x: T) = - inline x match { // error + inline x match { case _: Int => } foo(4) - foo("f") + foo("f") // error } \ No newline at end of file diff --git a/tests/neg/cannot-reduce-summonFrom.scala b/tests/neg/cannot-reduce-summonFrom.scala index f44f204ca230..bd8592b68fa4 100644 --- a/tests/neg/cannot-reduce-summonFrom.scala +++ b/tests/neg/cannot-reduce-summonFrom.scala @@ -1,7 +1,7 @@ object Test { inline def bar() = - compiletime.summonFrom { // error + compiletime.summonFrom { case _: Int => } @@ -10,5 +10,5 @@ object Test { bar() } - bar() + bar() // error } \ No newline at end of file diff --git a/tests/neg/i6371/A_1.scala b/tests/neg/i6371/A_1.scala index 9c7553af54ff..186ee85f6ed4 100644 --- a/tests/neg/i6371/A_1.scala +++ b/tests/neg/i6371/A_1.scala @@ -1,6 +1,6 @@ object A { inline def foo(a: Any): Unit = a match { - case _: Int => // error + case _: Int => case _ => } } diff --git a/tests/neg/i6371/B_2.scala b/tests/neg/i6371/B_2.scala index fcc88d22da42..a6bc955b6857 100644 --- a/tests/neg/i6371/B_2.scala +++ b/tests/neg/i6371/B_2.scala @@ -1,3 +1,3 @@ object B { - A.foo("aa") + A.foo("aa") // error } diff --git a/tests/neg/inline-error-pos.check b/tests/neg/inline-error-pos.check new file mode 100644 index 000000000000..2533dfa6384e --- /dev/null +++ b/tests/neg/inline-error-pos.check @@ -0,0 +1,9 @@ +-- Error: tests/neg/inline-error-pos.scala:3:11 ------------------------------------------------------------------------ +8 | val b = foo(2) // error + | ^^^^^^ + | cannot reduce inline match with + | scrutinee: { + | 2 + | } : Int(2) + | patterns : case 1 + | This location is in code that was inlined at inline-error-pos.scala:3 diff --git a/tests/neg/inline-error-pos.scala b/tests/neg/inline-error-pos.scala new file mode 100644 index 000000000000..5c85c15f9131 --- /dev/null +++ b/tests/neg/inline-error-pos.scala @@ -0,0 +1,9 @@ + +inline def foo(x: Int): Int = + inline x match + case 1 => 9 + +object Foo { + val a = foo(1) + val b = foo(2) // error +} \ No newline at end of file diff --git a/tests/neg/inlineAccess/C_1.scala b/tests/neg/inlineAccess/C_1.scala index 9d34fa3f0f1a..b3920c1dcc90 100644 --- a/tests/neg/inlineAccess/C_1.scala +++ b/tests/neg/inlineAccess/C_1.scala @@ -2,7 +2,7 @@ package p private class D class C { inline def inl(): Unit = { - val d = new D() // error (when inlined): not accessible + val d = new D() } } diff --git a/tests/neg/inlineAccess/Test_2.scala b/tests/neg/inlineAccess/Test_2.scala index 98ea7693abb7..73e829251e3e 100644 --- a/tests/neg/inlineAccess/Test_2.scala +++ b/tests/neg/inlineAccess/Test_2.scala @@ -2,6 +2,6 @@ object Test { def main(args: Array[String]) = { val c = new p.C() - c.inl() + c.inl() // error (when inlined): not accessible } } diff --git a/tests/neg/summonFrom-ambiguous-bind.scala b/tests/neg/summonFrom-ambiguous-bind.scala index 81c4091782e6..99f9f2e4a620 100644 --- a/tests/neg/summonFrom-ambiguous-bind.scala +++ b/tests/neg/summonFrom-ambiguous-bind.scala @@ -3,7 +3,7 @@ object `implicit-match-ambiguous-bind` { implicit val ibox: Box[Int] = Box(0) implicit val sbox: Box[String] = Box("") inline def unbox = compiletime.summonFrom { - case b: Box[t] => b.value // error + case b: Box[t] => b.value } - val unboxed = unbox + val unboxed = unbox // error } diff --git a/tests/neg/summonFrom-ambiguous.scala b/tests/neg/summonFrom-ambiguous.scala index 6e4cd6e343d8..2c05426b14d8 100644 --- a/tests/neg/summonFrom-ambiguous.scala +++ b/tests/neg/summonFrom-ambiguous.scala @@ -5,8 +5,8 @@ object Test { implicit val a2: A = new A inline def f: Any = compiletime.summonFrom { - case _: A => ??? // error: ambiguous implicits + case _: A => ??? } - f + f // error: ambiguous implicits } \ No newline at end of file From 0ca8423301a9cfda20febb5e655ea5b123366e65 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 4 Dec 2019 19:20:25 +0100 Subject: [PATCH 2/5] Update inline position error message --- .../src/dotty/tools/dotc/reporting/MessageRendering.scala | 2 +- tests/neg-macros/delegate-match-1.check | 2 +- tests/neg-macros/delegate-match-2.check | 2 +- tests/neg-macros/delegate-match-3.check | 2 +- tests/neg-macros/i6432.check | 6 +++--- tests/neg-macros/i6432b.check | 6 +++--- tests/neg-macros/i6976.check | 2 +- tests/neg-macros/macro-class-not-found-1.check | 2 +- tests/neg-macros/macro-class-not-found-2.check | 2 +- tests/neg-macros/macros-in-same-project-6.check | 2 +- tests/neg/cannot-reduce-inline-match.check | 2 +- tests/neg/inline-error-pos.check | 2 +- 12 files changed, 16 insertions(+), 16 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala b/compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala index 48b22a8f4057..e333f40c0c79 100644 --- a/compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala +++ b/compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala @@ -33,7 +33,7 @@ trait MessageRendering { */ def outer(pos: SourcePosition, prefix: String)(implicit ctx: Context): List[String] = if (pos.outer.exists) - i"$prefix| This location is in code that was inlined at $pos" :: + i"$prefix| This location contains code that was inlined from $pos" :: outer(pos.outer, prefix) else Nil diff --git a/tests/neg-macros/delegate-match-1.check b/tests/neg-macros/delegate-match-1.check index f6b1c7e1b4c4..6d88d021416f 100644 --- a/tests/neg-macros/delegate-match-1.check +++ b/tests/neg-macros/delegate-match-1.check @@ -4,4 +4,4 @@ | ^ | AmbiguousImplicits | both value a1 in class Test1 and value a2 in class Test1 match type A - | This location is in code that was inlined at Test_2.scala:6 + | This location contains code that was inlined from Test_2.scala:6 diff --git a/tests/neg-macros/delegate-match-2.check b/tests/neg-macros/delegate-match-2.check index 20b358a4d3b9..112e5ee00474 100644 --- a/tests/neg-macros/delegate-match-2.check +++ b/tests/neg-macros/delegate-match-2.check @@ -4,4 +4,4 @@ | ^ | DivergingImplicit | method a1 in class Test produces a diverging implicit search when trying to match type A - | This location is in code that was inlined at Test_2.scala:5 + | This location contains code that was inlined from Test_2.scala:5 diff --git a/tests/neg-macros/delegate-match-3.check b/tests/neg-macros/delegate-match-3.check index 55c24808f416..278aa92a4117 100644 --- a/tests/neg-macros/delegate-match-3.check +++ b/tests/neg-macros/delegate-match-3.check @@ -4,4 +4,4 @@ | ^ | NoMatchingImplicits | no implicit values were found that match type A - | This location is in code that was inlined at Test_2.scala:3 + | This location contains code that was inlined from Test_2.scala:3 diff --git a/tests/neg-macros/i6432.check b/tests/neg-macros/i6432.check index 706bfe7bae52..0e01f99be404 100644 --- a/tests/neg-macros/i6432.check +++ b/tests/neg-macros/i6432.check @@ -3,14 +3,14 @@ 4 | foo"abc${"123"}xyz${"456"}fgh" // error // error // error | ^^^ | abc - | This location is in code that was inlined at Test_2.scala:4 + | This location contains code that was inlined from Test_2.scala:4 -- Error: tests/neg-macros/i6432/Test_2.scala:4:17 --------------------------------------------------------------------- 4 | foo"abc${"123"}xyz${"456"}fgh" // error // error // error | ^^^ | xyz - | This location is in code that was inlined at Test_2.scala:4 + | This location contains code that was inlined from Test_2.scala:4 -- Error: tests/neg-macros/i6432/Test_2.scala:4:28 --------------------------------------------------------------------- 4 | foo"abc${"123"}xyz${"456"}fgh" // error // error // error | ^^^ | fgh - | This location is in code that was inlined at Test_2.scala:4 + | This location contains code that was inlined from Test_2.scala:4 diff --git a/tests/neg-macros/i6432b.check b/tests/neg-macros/i6432b.check index a0f8a64b2dc9..4dd1be84fa3c 100644 --- a/tests/neg-macros/i6432b.check +++ b/tests/neg-macros/i6432b.check @@ -3,14 +3,14 @@ 4 | foo"""abc${"123"}xyz${"456"}fgh""" // error // error // error | ^^^ | abc - | This location is in code that was inlined at Test_2.scala:4 + | This location contains code that was inlined from Test_2.scala:4 -- Error: tests/neg-macros/i6432b/Test_2.scala:4:19 -------------------------------------------------------------------- 4 | foo"""abc${"123"}xyz${"456"}fgh""" // error // error // error | ^^^ | xyz - | This location is in code that was inlined at Test_2.scala:4 + | This location contains code that was inlined from Test_2.scala:4 -- Error: tests/neg-macros/i6432b/Test_2.scala:4:30 -------------------------------------------------------------------- 4 | foo"""abc${"123"}xyz${"456"}fgh""" // error // error // error | ^^^ | fgh - | This location is in code that was inlined at Test_2.scala:4 + | This location contains code that was inlined from Test_2.scala:4 diff --git a/tests/neg-macros/i6976.check b/tests/neg-macros/i6976.check index 6cd7aa494345..462a319452a8 100644 --- a/tests/neg-macros/i6976.check +++ b/tests/neg-macros/i6976.check @@ -6,4 +6,4 @@ | scala.MatchError: Inlined(EmptyTree,List(),Literal(Constant(2))) (of class dotty.tools.dotc.ast.Trees$Inlined) | at playground.macros$.mcrImpl(Macro_1.scala:12) | - | This location is in code that was inlined at Test_2.scala:5 + | This location contains code that was inlined from Test_2.scala:5 diff --git a/tests/neg-macros/macro-class-not-found-1.check b/tests/neg-macros/macro-class-not-found-1.check index 4117c7cb0b45..445523c6ade2 100644 --- a/tests/neg-macros/macro-class-not-found-1.check +++ b/tests/neg-macros/macro-class-not-found-1.check @@ -5,4 +5,4 @@ | java.lang.NoClassDefFoundError | at Foo$.aMacroImplementation(Foo.scala:8) | - | This location is in code that was inlined at Bar.scala:4 + | This location contains code that was inlined from Bar.scala:4 diff --git a/tests/neg-macros/macro-class-not-found-2.check b/tests/neg-macros/macro-class-not-found-2.check index fbeac29d33c1..3cb7506e6bb2 100644 --- a/tests/neg-macros/macro-class-not-found-2.check +++ b/tests/neg-macros/macro-class-not-found-2.check @@ -5,4 +5,4 @@ | java.lang.NoClassDefFoundError: this.is.not.a.Class | at Foo$.aMacroImplementation(Foo.scala:8) | - | This location is in code that was inlined at Bar.scala:4 + | This location contains code that was inlined from Bar.scala:4 diff --git a/tests/neg-macros/macros-in-same-project-6.check b/tests/neg-macros/macros-in-same-project-6.check index 989cae136283..485f5062db92 100644 --- a/tests/neg-macros/macros-in-same-project-6.check +++ b/tests/neg-macros/macros-in-same-project-6.check @@ -2,4 +2,4 @@ 4 | Foo.myMacro() // error | ^^^^^^^^^^^^^ | some error - | This location is in code that was inlined at Bar.scala:4 + | This location contains code that was inlined from Bar.scala:4 diff --git a/tests/neg/cannot-reduce-inline-match.check b/tests/neg/cannot-reduce-inline-match.check index deef3789ddf5..b631d029f85e 100644 --- a/tests/neg/cannot-reduce-inline-match.check +++ b/tests/neg/cannot-reduce-inline-match.check @@ -6,4 +6,4 @@ | "f" | } : String("f") | patterns : case _:Int - | This location is in code that was inlined at cannot-reduce-inline-match.scala:3 + | This location contains code that was inlined from cannot-reduce-inline-match.scala:3 diff --git a/tests/neg/inline-error-pos.check b/tests/neg/inline-error-pos.check index 2533dfa6384e..2d839fd45536 100644 --- a/tests/neg/inline-error-pos.check +++ b/tests/neg/inline-error-pos.check @@ -6,4 +6,4 @@ | 2 | } : Int(2) | patterns : case 1 - | This location is in code that was inlined at inline-error-pos.scala:3 + | This location contains code that was inlined from inline-error-pos.scala:3 From 29744feefcb5fdc6341b95d68e272af0fc636571 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 4 Dec 2019 19:34:17 +0100 Subject: [PATCH 3/5] Update error message header --- .../src/dotty/tools/dotc/reporting/MessageRendering.scala | 4 ++-- project/scripts/cmdTests | 2 +- tests/neg/cannot-reduce-inline-match.check | 2 +- tests/neg/inline-error-pos.check | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala b/compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala index e333f40c0c79..ef912c3bf61e 100644 --- a/compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala +++ b/compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala @@ -114,9 +114,9 @@ trait MessageRendering { */ def posStr(pos: SourcePosition, diagnosticLevel: String, message: Message)(implicit ctx: Context): String = if (pos.exists) hl(diagnosticLevel)({ + val pos1 = pos.nonInlined val file = - if (pos.source.file.exists) s"${pos.source.file.toString}:${pos.line + 1}:${pos.column}" - else s"${pos.source.file.toString}: offset ${pos.start} (missing source file)" + s"${pos1.source.file.toString}:${pos1.line + 1}:${pos1.column}" val errId = if (message.errorId ne ErrorMessageID.NoExplanationID) { val errorNumber = message.errorId.errorNumber diff --git a/project/scripts/cmdTests b/project/scripts/cmdTests index 542dcf3feecb..7bbc2d97aa85 100755 --- a/project/scripts/cmdTests +++ b/project/scripts/cmdTests @@ -50,7 +50,7 @@ cp tests/neg/i6371/B_2.scala $OUT/B.scala "$SBT" "dotc $OUT/A.scala -d $OUT1" rm $OUT/A.scala "$SBT" "dotc -classpath $OUT1 -d $OUT1 $OUT/B.scala" > "$tmp" 2>&1 || echo "ok" -grep -qe "A.scala: offset 63 (missing source file)" "$tmp" +grep -qe "B.scala:2:7" "$tmp" ## Disabled because of flakeyness, should be changed to not depend on sbt diff --git a/tests/neg/cannot-reduce-inline-match.check b/tests/neg/cannot-reduce-inline-match.check index b631d029f85e..f66966096118 100644 --- a/tests/neg/cannot-reduce-inline-match.check +++ b/tests/neg/cannot-reduce-inline-match.check @@ -1,4 +1,4 @@ --- Error: tests/neg/cannot-reduce-inline-match.scala:3:13 -------------------------------------------------------------- +-- Error: tests/neg/cannot-reduce-inline-match.scala:9:5 --------------------------------------------------------------- 9 | foo("f") // error | ^^^^^^^^ | cannot reduce inline match with diff --git a/tests/neg/inline-error-pos.check b/tests/neg/inline-error-pos.check index 2d839fd45536..4c92d7ef3ce4 100644 --- a/tests/neg/inline-error-pos.check +++ b/tests/neg/inline-error-pos.check @@ -1,4 +1,4 @@ --- Error: tests/neg/inline-error-pos.scala:3:11 ------------------------------------------------------------------------ +-- Error: tests/neg/inline-error-pos.scala:8:13 ------------------------------------------------------------------------ 8 | val b = foo(2) // error | ^^^^^^ | cannot reduce inline match with From bb8642ea1308d3e45c715fff92215273f07d5c04 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 5 Dec 2019 11:08:45 +0100 Subject: [PATCH 4/5] Move error locations --- tests/neg/i7618.scala | 4 ++-- tests/neg/i7618b.scala | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/neg/i7618.scala b/tests/neg/i7618.scala index 42c68bb8de4a..f1566ee0a7fb 100644 --- a/tests/neg/i7618.scala +++ b/tests/neg/i7618.scala @@ -12,7 +12,7 @@ enum Exp { object Compiler { import Exp._ - inline def compile(e: Exp, env: Map[String, Expr[Int]])(given ctx: QuoteContext): Expr[Int] = inline e match { // error + inline def compile(e: Exp, env: Map[String, Expr[Int]])(given ctx: QuoteContext): Expr[Int] = inline e match { case Num(n) => Expr(n) case Plus(e1, e2) => @@ -31,6 +31,6 @@ object Example { val exp = Plus(Plus(Num(2), Var("x")), Num(4)) val letExp = Let("x", Num(3), exp) - Compiler.compile(letExp, Map.empty)(given QuoteContext.macroContext) // error + Compiler.compile(letExp, Map.empty)(given QuoteContext.macroContext) // error // error } } diff --git a/tests/neg/i7618b.scala b/tests/neg/i7618b.scala index d69e6299826f..f756ff890179 100644 --- a/tests/neg/i7618b.scala +++ b/tests/neg/i7618b.scala @@ -12,7 +12,7 @@ enum Exp { object Compiler { import Exp._ - inline def compile(e: Exp, env: Map[String, Expr[Int]])(given ctx: QuoteContext): Expr[Int] = inline e match { // error + inline def compile(e: Exp, env: Map[String, Expr[Int]])(given ctx: QuoteContext): Expr[Int] = inline e match { case Num(n) => Expr(n) case Plus(e1, e2) => @@ -31,6 +31,6 @@ object Example { val exp = Plus(Plus(Num(2), Var("x")), Num(4)) val letExp = Let("x", Num(3), exp) - Compiler.compile(letExp, Map.empty)(given (??? : QuoteContext)) + Compiler.compile(letExp, Map.empty)(given (??? : QuoteContext)) // error } } From fb8ac6c75eea5a92d5f8951fe976cfb0ee8af7aa Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 5 Dec 2019 11:48:56 +0100 Subject: [PATCH 5/5] Update compiler/src/dotty/tools/dotc/util/SourcePosition.scala Co-Authored-By: Anatolii Kmetiuk --- compiler/src/dotty/tools/dotc/util/SourcePosition.scala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/util/SourcePosition.scala b/compiler/src/dotty/tools/dotc/util/SourcePosition.scala index 65acfa47dac2..5aee6965fbaf 100644 --- a/compiler/src/dotty/tools/dotc/util/SourcePosition.scala +++ b/compiler/src/dotty/tools/dotc/util/SourcePosition.scala @@ -70,7 +70,7 @@ extends interfaces.SourcePosition with Showable { def nonInlined: SourcePosition = { val om = outermost def rec(self: SourcePosition): SourcePosition = - if outermost.contains(self) then self else rec(self.outer) + if om.contains(self) then self else rec(self.outer) rec(this) } @@ -86,4 +86,3 @@ extends interfaces.SourcePosition with Showable { override def toString: String = "?" override def withOuter(outer: SourcePosition): SourcePosition = outer } -