Skip to content

Commit a293cf6

Browse files
committed
Fix #16173: Give a non-synthetic span to singleton literal types.
1 parent 62684d0 commit a293cf6

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1725,7 +1725,8 @@ object Parsers {
17251725
*/
17261726
def simpleType(): Tree =
17271727
if isSimpleLiteral then
1728-
SingletonTypeTree(simpleLiteral())
1728+
val lit = simpleLiteral()
1729+
SingletonTypeTree(lit).withSpan(lit.span)
17291730
else if in.token == USCORE then
17301731
if ctx.settings.YkindProjector.value == "underscores" then
17311732
val start = in.skipToken()

tests/sjs-junit/test/org/scalajs/testsuite/compiler/RegressionTestScala3.scala

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ class RegressionTestScala3 {
7878
val f3 = { () => i += 1 }
7979
assertSame(f3, Thunk.asFunction0(f3()))
8080
}
81+
82+
@Test def literalTypeJSNativeIssue16173(): Unit = {
83+
js.eval("""
84+
var RegressionTestScala3_Issue16173_foo = "constant";
85+
var RegressionTestScala3_Issue16173_bar = function() { return 5; };
86+
""")
87+
88+
assertEquals("constant", Issue16173.foo1)
89+
assertEquals("constant", Issue16173.foo2)
90+
91+
assertEquals(5, Issue16173.bar1())
92+
}
8193
}
8294

8395
object RegressionTestScala3 {
@@ -148,6 +160,20 @@ object RegressionTestScala3 {
148160
val entries = js.Object.entries(obj)
149161
val js.Tuple2(k, v) = entries(0): @unchecked
150162
}
163+
164+
object Issue16173 {
165+
@js.native
166+
@JSGlobal("RegressionTestScala3_Issue16173_foo")
167+
val foo1: "constant" = js.native
168+
169+
@js.native
170+
@JSGlobal("RegressionTestScala3_Issue16173_foo")
171+
def foo2: "constant" = js.native
172+
173+
@js.native
174+
@JSGlobal("RegressionTestScala3_Issue16173_bar")
175+
def bar1(): 5 = js.native
176+
}
151177
}
152178

153179
// This class needs to be at the top-level, not in an object, to reproduce the issue

0 commit comments

Comments
 (0)