File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed
compiler/src/dotty/tools/dotc/transform/sjs
tests/sjs-junit/test/org/scalajs/testsuite/compiler Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -979,9 +979,9 @@ class PrepJSInterop extends MacroTransform with IdentityDenotTransformer { thisP
979979 report.error(s " $longKindStr may only call js.native. " , pos)
980980 }
981981
982- // Check that the resul type was explicitly specified
982+ // Check that the result type was explicitly specified
983983 // (This is stronger than Scala 2, which only warns, and only if it was inferred as Nothing.)
984- if (tree.tpt.span.isSynthetic )
984+ if (tree.tpt.isInstanceOf [ InferredTypeTree ] )
985985 report.error(i " The type of ${tree.name} must be explicitly specified because it is JS native. " , tree)
986986 }
987987
Original file line number Diff line number Diff 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
8395object 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
You can’t perform that action at this time.
0 commit comments