Skip to content

Commit

Permalink
Fix #16173: Give a non-synthetic span to singleton literal types.
Browse files Browse the repository at this point in the history
  • Loading branch information
sjrd committed Oct 14, 2022
1 parent 62684d0 commit a293cf6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1725,7 +1725,8 @@ object Parsers {
*/
def simpleType(): Tree =
if isSimpleLiteral then
SingletonTypeTree(simpleLiteral())
val lit = simpleLiteral()
SingletonTypeTree(lit).withSpan(lit.span)
else if in.token == USCORE then
if ctx.settings.YkindProjector.value == "underscores" then
val start = in.skipToken()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ class RegressionTestScala3 {
val f3 = { () => i += 1 }
assertSame(f3, Thunk.asFunction0(f3()))
}

@Test def literalTypeJSNativeIssue16173(): Unit = {
js.eval("""
var RegressionTestScala3_Issue16173_foo = "constant";
var RegressionTestScala3_Issue16173_bar = function() { return 5; };
""")

assertEquals("constant", Issue16173.foo1)
assertEquals("constant", Issue16173.foo2)

assertEquals(5, Issue16173.bar1())
}
}

object RegressionTestScala3 {
Expand Down Expand Up @@ -148,6 +160,20 @@ object RegressionTestScala3 {
val entries = js.Object.entries(obj)
val js.Tuple2(k, v) = entries(0): @unchecked
}

object Issue16173 {
@js.native
@JSGlobal("RegressionTestScala3_Issue16173_foo")
val foo1: "constant" = js.native

@js.native
@JSGlobal("RegressionTestScala3_Issue16173_foo")
def foo2: "constant" = js.native

@js.native
@JSGlobal("RegressionTestScala3_Issue16173_bar")
def bar1(): 5 = js.native
}
}

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

0 comments on commit a293cf6

Please sign in to comment.