From e58f7ef7df6979417ce131202709204283cc7976 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Doeraene?= Date: Tue, 28 Jul 2020 17:58:11 +0200 Subject: [PATCH 1/2] Emit a compile error for non-native JS classes instead of crashing. This allows to immediately know what file is problematic. --- .../dotty/tools/backend/sjs/JSCodeGen.scala | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala b/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala index 843860b4fd0e..d47042ca7480 100644 --- a/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala +++ b/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala @@ -384,7 +384,31 @@ class JSCodeGen()(using genCtx: Context) { /** Gen the IR ClassDef for a Scala.js-defined JS class. */ private def genScalaJSDefinedJSClass(td: TypeDef): js.ClassDef = { - ??? + val sym = td.symbol.asClass + implicit val pos: SourcePosition = sym.sourcePos + + assert(!sym.is(Trait), + "genScalaJSDefinedJSClass() must be called only for normal classes: "+sym) + assert(sym.superClass != NoSymbol, sym) + + val classIdent = encodeClassNameIdent(sym) + val originalName = originalNameOfClass(sym) + + report.error("cannot emit non-native JS classes yet", td.sourcePos) + + // Dummy result + js.ClassDef( + classIdent, + originalName, + ClassKind.JSClass, + None, + Some(encodeClassNameIdent(sym.superClass)), + genClassInterfaces(sym), + None, + None, + Nil, + Nil)( + OptimizerHints.empty) } /** Gen the IR ClassDef for a raw JS class or trait. From 82f9a30134399428ef03578e38ddaf2718a5e4de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Doeraene?= Date: Tue, 28 Jul 2020 17:59:26 +0200 Subject: [PATCH 2/2] Scala.js: Enable JS-specific tests that already pass. --- project/Build.scala | 80 ++++++++++++++++++++++++++++ project/TestSuiteLinkerOptions.scala | 39 ++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 project/TestSuiteLinkerOptions.scala diff --git a/project/Build.scala b/project/Build.scala index dd5b55871190..f8043ea0767f 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -1008,6 +1008,9 @@ object Build { ) }.taskValue, + scalaJSLinkerConfig ~= { _.withSemantics(build.TestSuiteLinkerOptions.semantics _) }, + scalaJSModuleInitializers in Test ++= build.TestSuiteLinkerOptions.moduleInitializers, + managedSources in Compile ++= { val dir = fetchScalaJSSource.value / "test-suite/js/src/main/scala" val filter = ( @@ -1063,6 +1066,83 @@ object Build { ++ (dir / "shared/src/test/require-jdk7/org/scalajs/testsuite/javalib/io" ** "*.scala").get ++ (dir / "shared/src/test/require-jdk7/org/scalajs/testsuite/javalib/lang" ** "*.scala").get ++ (dir / "shared/src/test/require-jdk7/org/scalajs/testsuite/javalib/util" ** "*.scala").get + + ++ (dir / "js/src/test/scala/org/scalajs/testsuite/compiler" ** (("*.scala": FileFilter) + -- "InteroperabilityTest.scala" // various compile errors + -- "OptimizerTest.scala" // compile errors: false + string and () + string + -- "ReflectionTest.scala" // tests fail + -- "RegressionJSTest.scala" // compile error with js.Dynamic.literal + -- "RuntimeTypesTest.scala" // compile errors: no ClassTag for Null and Nothing + )).get + + ++ (dir / "js/src/test/scala/org/scalajs/testsuite/javalib" ** (("*.scala": FileFilter) + -- "FormatterJSTest.scala" // compile error with the f"" interpolator + -- "ObjectJSTest.scala" // non-native JS classes + -- "StringBufferJSTest.scala" // IR checking errors + -- "ThrowableJSTest.scala" // test fails ("java.lang.Error: stub") + )).get + + ++ (dir / "js/src/test/scala/org/scalajs/testsuite/jsinterop" ** (("*.scala": FileFilter) + -- "AsyncTest.scala" // needs PromiseMock.scala + -- "DynamicTest.scala" // compile error with js.Dynamic.literal + -- "ExportsTest.scala" // JS exports + -- "FunctionTest.scala" // IR checking errors + -- "IterableTest.scala" // non-native JS classes + -- "JSExportStaticTest.scala" // JS exports + -- "JSNameTest.scala" // compile error with js.Dynamic.literal + -- "JSNativeInPackage.scala" // IR checking errors + -- "JSOptionalTest.scala" // non-native JS classes + -- "JSSymbolTest.scala" // compile error with js.Dynamic.literal + -- "MiscInteropTest.scala" // compile error with js.Dynamic.literal + -- "ModulesWithGlobalFallbackTest.scala" // non-native JS classes + -- "NestedJSClassTest.scala" // non-native JS classes + -- "NonNativeJSTypeTest.scala" // non-native JS classes + -- "PromiseMock.scala" // non-native JS classes + -- "SpecialTest.scala" // compile error with js.Dynamic.literal + -- "SymbolTest.scala" // IR checking errors + -- "ThisFunctionTest.scala" // compile error with js.Dynamic.literal + -- "UndefOrTest.scala" // StackOverflow in the compiler + )).get + + ++ (dir / "js/src/test/scala/org/scalajs/testsuite/junit" ** (("*.scala": FileFilter) + // Tests fail + -- "JUnitAbstractClassTest.scala" + -- "JUnitNamesTest.scala" + -- "JUnitSubClassTest.scala" + -- "MultiCompilationSecondUnitTest.scala" + )).get + + ++ (dir / "js/src/test/scala/org/scalajs/testsuite/library" ** (("*.scala": FileFilter) + -- "BigIntTest.scala" // StackOverflow in the compiler + -- "ObjectTest.scala" // compile errors + -- "StackTraceTest.scala" // would require `npm install source-map-support` + -- "UnionTypeTest.scala" // requires a Scala 2 macro + StackOverflow in the compiler + -- "WrappedDictionaryTest.scala" // IR checking errors + )).get + + ++ (dir / "js/src/test/scala/org/scalajs/testsuite/niobuffer" ** "*.scala").get + + ++ (dir / "js/src/test/scala/org/scalajs/testsuite/scalalib" ** (("*.scala": FileFilter) + -- "ScalaRunTimeJSTest.scala" // compile error with js.Dynamic.literal + )).get + + ++ (dir / "js/src/test/scala/org/scalajs/testsuite/typedarray" ** (("*.scala": FileFilter) + -- "TypedArrayTest.scala" // assertion error in ExpandSAMs + )).get + + ++ (dir / "js/src/test/scala/org/scalajs/testsuite/utils" ** "*.scala").get + + ++ (dir / "js/src/test/require-2.12" ** (("*.scala": FileFilter) + -- "JSOptionalTest212.scala" // non-native JS classes + )).get + + ++ (dir / "js/src/test/require-sam" ** (("*.scala": FileFilter) + -- "SAMJSTest.scala" // non-native JS classes + )).get + + ++ (dir / "js/src/test/scala-new-collections" ** (("*.scala": FileFilter) + -- "WrappedDictionaryToTest.scala" // IR checking errors + )).get ) } ) diff --git a/project/TestSuiteLinkerOptions.scala b/project/TestSuiteLinkerOptions.scala new file mode 100644 index 000000000000..69fa7d2737f4 --- /dev/null +++ b/project/TestSuiteLinkerOptions.scala @@ -0,0 +1,39 @@ +package build + +// This file is an exact copy of the file of the same name in scala-js/scala-js + +import org.scalajs.linker.interface._ + +object TestSuiteLinkerOptions { + + def semantics(s: Semantics): Semantics = { + import Semantics.RuntimeClassNameMapper + + s.withRuntimeClassNameMapper( + RuntimeClassNameMapper.keepAll().andThen( + RuntimeClassNameMapper.regexReplace( + raw"""^org\.scalajs\.testsuite\.compiler\.ReflectionTest\$$RenamedTestClass$$""".r, + "renamed.test.Class") + ).andThen( + RuntimeClassNameMapper.regexReplace( + raw"""^org\.scalajs\.testsuite\.compiler\.ReflectionTest\$$Prefix""".r, + "renamed.test.byprefix.") + ).andThen( + RuntimeClassNameMapper.regexReplace( + raw"""^org\.scalajs\.testsuite\.compiler\.ReflectionTest\$$OtherPrefix""".r, + "renamed.test.byotherprefix.") + ) + ) + } + + def moduleInitializers: List[ModuleInitializer] = { + val module = "org.scalajs.testsuite.compiler.ModuleInitializers" + List( + ModuleInitializer.mainMethod(module, "mainNoArgs"), + ModuleInitializer.mainMethodWithArgs(module, "mainWithArgs"), + ModuleInitializer.mainMethodWithArgs(module, "mainWithArgs", List("foo", "bar")), + ModuleInitializer.mainMethod(module + "$NoLinkedClass", "main"), + ModuleInitializer.mainMethod(module + "$WithLinkedClass", "main") + ) + } +}