File tree 2 files changed +28
-2
lines changed
compiler/src/dotty/tools/dotc/transform/sjs
tests/sjs-junit/test/org/scalajs/testsuite/compiler
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
979
979
report.error(s " $longKindStr may only call js.native. " , pos)
980
980
}
981
981
982
- // Check that the resul type was explicitly specified
982
+ // Check that the result type was explicitly specified
983
983
// (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 ] )
985
985
report.error(i " The type of ${tree.name} must be explicitly specified because it is JS native. " , tree)
986
986
}
987
987
Original file line number Diff line number Diff line change @@ -78,6 +78,18 @@ class RegressionTestScala3 {
78
78
val f3 = { () => i += 1 }
79
79
assertSame(f3, Thunk .asFunction0(f3()))
80
80
}
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
+ }
81
93
}
82
94
83
95
object RegressionTestScala3 {
@@ -148,6 +160,20 @@ object RegressionTestScala3 {
148
160
val entries = js.Object .entries(obj)
149
161
val js .Tuple2 (k, v) = entries(0 ): @ unchecked
150
162
}
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
+ }
151
177
}
152
178
153
179
// 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