From 1688a6bbccedd4eee4a407bdc44f555f229582a3 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Sun, 14 Apr 2024 11:20:48 -0700 Subject: [PATCH] Slightly improved import pos --- src/compiler/scala/tools/nsc/ast/parser/Parsers.scala | 2 +- src/compiler/scala/tools/nsc/typechecker/Namers.scala | 6 ++++-- src/reflect/scala/reflect/internal/util/Position.scala | 3 ++- test/files/run/interop_typetags_are_manifests.scala | 2 -- test/files/run/macro-openmacros.check | 6 +++--- test/files/run/macro-openmacros/Impls_Macros_1.scala | 1 - test/files/run/macro-openmacros/Test_2.scala | 1 - test/files/run/macro-parse-position.check | 2 +- test/files/run/macro-parse-position/Impls_Macros_1.scala | 1 - test/files/run/macro-parse-position/Test_2.scala | 1 - test/files/run/macroPlugins-typedMacroBody/Macros_2.scala | 2 +- test/files/run/macroPlugins-typedMacroBody/Plugin_1.scala | 1 - test/files/run/macroPlugins-typedMacroBody/Test_3.scala | 1 - test/files/run/t6663.scala | 2 -- test/files/run/t6731.scala | 2 -- 15 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index 872c130bd80d..1fbe80e2331d 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -2731,7 +2731,7 @@ self => case Nil => Nil case t :: rest => // The first import should start at the position of the keyword. - t.setPos(t.pos.withStart(offset)) + if (t.pos.isRange) t.setPos(t.pos.withStart(offset)) t :: rest } } diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index d6cbe6d42711..9dae1d19b3f4 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -589,8 +589,10 @@ trait Namers extends MethodSynthesis { // so don't warn for them. There is a corresponding special treatment // in the shadowing rules in typedIdent to (scala/bug#7232). In any case, // we shouldn't be emitting warnings for .java source files. - if (!context.unit.isJava) - checkNotRedundant(tree.pos withPoint fromPos, from, to) + if (!context.unit.isJava) { + val at = if (tree.pos.isRange) tree.pos.withPoint(fromPos) else tree.pos + checkNotRedundant(at, from, to) + } } } selectors.foreach(checkSelector) diff --git a/src/reflect/scala/reflect/internal/util/Position.scala b/src/reflect/scala/reflect/internal/util/Position.scala index 6ef97044b8ff..6ffa24796ff4 100644 --- a/src/reflect/scala/reflect/internal/util/Position.scala +++ b/src/reflect/scala/reflect/internal/util/Position.scala @@ -40,7 +40,8 @@ object Position { if (pos.isRange) { import pos.{pos => _, _} assert(start <= end, s"bad position: ${pos.show}") - //assert(start <= point && point < end, s"bad position: point $point out of range $start..$end: ${pos.show}") + //assert(start <= point && point <= end, s"bad position: point $point out of range $start..$end: ${pos.show}") + //assert(start <= point && point <= end, s"bad position: point $point out of range $start..$end: ${pos.show}\n${pos.lineContent}\n${pos.lineCaret}") } pos } diff --git a/test/files/run/interop_typetags_are_manifests.scala b/test/files/run/interop_typetags_are_manifests.scala index 3eb36e292c2c..5b8935106baf 100644 --- a/test/files/run/interop_typetags_are_manifests.scala +++ b/test/files/run/interop_typetags_are_manifests.scala @@ -1,5 +1,3 @@ -// scalac: -Yrangepos:false -// import scala.reflect.runtime.universe._ import scala.reflect.ClassTag diff --git a/test/files/run/macro-openmacros.check b/test/files/run/macro-openmacros.check index 81cd1bbba5c2..41f01e3bdc04 100644 --- a/test/files/run/macro-openmacros.check +++ b/test/files/run/macro-openmacros.check @@ -1,3 +1,3 @@ -List(MacroContext(foo@source-Test_2.scala,line-3,offset=63 +0)) -List(MacroContext(foo@source-Test_2.scala,line-3,offset=63 +1), MacroContext(foo@source-Test_2.scala,line-3,offset=63 +0)) -List(MacroContext(foo@source-Test_2.scala,line-3,offset=63 +2), MacroContext(foo@source-Test_2.scala,line-3,offset=63 +1), MacroContext(foo@source-Test_2.scala,line-3,offset=63 +0)) +List(MacroContext(foo@RangePosition(Test_2.scala, 28, 35, 38) +0)) +List(MacroContext(foo@source-Test_2.scala,line-2,offset=35 +1), MacroContext(foo@RangePosition(Test_2.scala, 28, 35, 38) +0)) +List(MacroContext(foo@source-Test_2.scala,line-2,offset=35 +2), MacroContext(foo@source-Test_2.scala,line-2,offset=35 +1), MacroContext(foo@RangePosition(Test_2.scala, 28, 35, 38) +0)) diff --git a/test/files/run/macro-openmacros/Impls_Macros_1.scala b/test/files/run/macro-openmacros/Impls_Macros_1.scala index 3ab0ed3720d2..1082b8aab157 100644 --- a/test/files/run/macro-openmacros/Impls_Macros_1.scala +++ b/test/files/run/macro-openmacros/Impls_Macros_1.scala @@ -1,4 +1,3 @@ -// scalac: -Yrangepos:false import scala.language.experimental.macros import scala.reflect.macros.blackbox.Context import scala.util.Properties.isWin diff --git a/test/files/run/macro-openmacros/Test_2.scala b/test/files/run/macro-openmacros/Test_2.scala index 8a085961570d..5d19639cddff 100644 --- a/test/files/run/macro-openmacros/Test_2.scala +++ b/test/files/run/macro-openmacros/Test_2.scala @@ -1,4 +1,3 @@ -// scalac: -Yrangepos:false object Test extends App { Macros.foo } diff --git a/test/files/run/macro-parse-position.check b/test/files/run/macro-parse-position.check index 3da0320696d2..feceb9fac88f 100644 --- a/test/files/run/macro-parse-position.check +++ b/test/files/run/macro-parse-position.check @@ -1,5 +1,5 @@ false -source-,line-1,offset=4 +RangePosition(, 0, 4, 7) 8 foo bar diff --git a/test/files/run/macro-parse-position/Impls_Macros_1.scala b/test/files/run/macro-parse-position/Impls_Macros_1.scala index a17f0cdbfa63..989360cdf6f3 100644 --- a/test/files/run/macro-parse-position/Impls_Macros_1.scala +++ b/test/files/run/macro-parse-position/Impls_Macros_1.scala @@ -1,4 +1,3 @@ -// scalac: -Yrangepos:false import scala.language.experimental.macros import scala.reflect.macros.blackbox.Context diff --git a/test/files/run/macro-parse-position/Test_2.scala b/test/files/run/macro-parse-position/Test_2.scala index db0bac2510ff..cff569bd81b1 100644 --- a/test/files/run/macro-parse-position/Test_2.scala +++ b/test/files/run/macro-parse-position/Test_2.scala @@ -1,4 +1,3 @@ -// scalac: -Yrangepos:false object Test extends App { println(Macros.foo) } diff --git a/test/files/run/macroPlugins-typedMacroBody/Macros_2.scala b/test/files/run/macroPlugins-typedMacroBody/Macros_2.scala index 7dafd5bfac91..df48620087af 100644 --- a/test/files/run/macroPlugins-typedMacroBody/Macros_2.scala +++ b/test/files/run/macroPlugins-typedMacroBody/Macros_2.scala @@ -1,4 +1,4 @@ -// scalac: -Xplugin:. -Yrangepos:false +//> using options -Xplugin:. import scala.language.experimental.macros import scala.reflect.macros.blackbox.Context diff --git a/test/files/run/macroPlugins-typedMacroBody/Plugin_1.scala b/test/files/run/macroPlugins-typedMacroBody/Plugin_1.scala index b9445dd9d30a..18ad54fe8604 100644 --- a/test/files/run/macroPlugins-typedMacroBody/Plugin_1.scala +++ b/test/files/run/macroPlugins-typedMacroBody/Plugin_1.scala @@ -1,4 +1,3 @@ -// scalac: -Yrangepos:false package typedMacroBody import scala.tools.nsc.Global diff --git a/test/files/run/macroPlugins-typedMacroBody/Test_3.scala b/test/files/run/macroPlugins-typedMacroBody/Test_3.scala index 360d9bbaa0f6..98eafcb6b2bc 100644 --- a/test/files/run/macroPlugins-typedMacroBody/Test_3.scala +++ b/test/files/run/macroPlugins-typedMacroBody/Test_3.scala @@ -1,4 +1,3 @@ -// scalac: -Yrangepos:false object Test extends App { Macros.foo1 Macros.foo2 diff --git a/test/files/run/t6663.scala b/test/files/run/t6663.scala index e93dca2afdbd..d41d76ffe921 100644 --- a/test/files/run/t6663.scala +++ b/test/files/run/t6663.scala @@ -1,5 +1,3 @@ -// scalac: -Yrangepos:false -// import language.dynamics class C(v: Any) extends Dynamic { diff --git a/test/files/run/t6731.scala b/test/files/run/t6731.scala index 8ea4962558dc..f246010a893e 100644 --- a/test/files/run/t6731.scala +++ b/test/files/run/t6731.scala @@ -1,5 +1,3 @@ -// scalac: -Yrangepos:false -deprecation -// import scala.language.dynamics import scala.reflect.{ ClassTag, classTag }