Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotc -target option problem #8633

Closed
ohze opened this issue Mar 30, 2020 · 3 comments
Closed

dotc -target option problem #8633

ohze opened this issue Mar 30, 2020 · 3 comments

Comments

@ohze
Copy link

ohze commented Mar 30, 2020

Some problems related to dotc target option:

  • compile error targets: msil, jvm-1.5-fjbg, jvm-1.5-asm:
% echo '@main def hi() = println("hi!")' > hi.scala
% dotc -target:jvm-1.5-asm hi.scala
exception occurred while compiling hi.scala
scala.MatchError: jvm-1.5-asm (of class java.lang.String) while compiling hi.scala
Exception in thread "main" scala.MatchError: jvm-1.5-asm (of class java.lang.String)
	at dotty.tools.backend.jvm.BCodeIdiomatic.classfileVersion(BCodeIdiomatic.scala:30)

The error is caused by this: BCodeIdiomatic.scala

  • (maybe?) runtime error targets: jvm-1.5, jvm-1.6, jvm-1.7
    dotc -target:jvm-1.5-asm hi.scala success but I think we cannot run the output classes with jvm 1.5?

  • don't have targets 9 to 15 which scala 2.13 has.

  • similar, scalac has option -release 9. IDK supporting this option in dotc is hard or not?
    EDIT: I have created a separated issue support -release option #8634 for -release option

@ohze ohze added the itype:bug label Mar 30, 2020
@ohze
Copy link
Author

ohze commented Mar 30, 2020

A quick fix about -target option:

% git diff -U0      
diff --git a/compiler/src/dotty/tools/backend/jvm/BCodeIdiomatic.scala b/compiler/src/dotty/tools/backend/jvm/BCodeIdiomatic.scala
index 81e3284e1f..8dcb18f76c 100644
--- a/compiler/src/dotty/tools/backend/jvm/BCodeIdiomatic.scala
+++ b/compiler/src/dotty/tools/backend/jvm/BCodeIdiomatic.scala
@@ -26,6 +26,2 @@ trait BCodeIdiomatic {
-  lazy val classfileVersion: Int = targetPlatform match {
-    case "jvm-1.5"     => asm.Opcodes.V1_5
-    case "jvm-1.6"     => asm.Opcodes.V1_6
-    case "jvm-1.7"     => asm.Opcodes.V1_7
-    case "jvm-1.8"     => asm.Opcodes.V1_8
-  }
+  /** return [[scala.tools.asm.Opcodes.V1_8]] == 52 for `targetPlatform` "jvm-1.8" | "8" and so on */
+  lazy val classfileVersion: Int = targetPlatform.stripPrefix("jvm-1.").toInt + 44
diff --git a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
index e1ec597d75..b69b8b79e0 100644
--- a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
+++ b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
@@ -38 +38 @@ class ScalaSettings extends Settings.SettingGroup {
-    List("jvm-1.5", "jvm-1.5-fjbg", "jvm-1.5-asm", "jvm-1.6", "jvm-1.7", "jvm-1.8", "msil"), "jvm-1.8") withAbbreviation "--target"
+    (8 to 15).flatMap(v => Seq(s"$v", s"jvm-1.$v")).toList, "8") withAbbreviation "--target"

At least I can compile & run the hi.scala program above with this fix :)

@ohze ohze changed the title dotc -target, -release options problem dotc -target option problem Mar 30, 2020
@smarter
Copy link
Member

smarter commented Apr 6, 2020

We can't properly support -target 9 or above because we haven't fixed #1441 (comment) yet.

@anatoliykmetyuk anatoliykmetyuk removed their assignment Nov 24, 2020
@smarter
Copy link
Member

smarter commented Jan 5, 2021

This was fixed in #9181

@smarter smarter closed this as completed Jan 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants