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

coverage compilation fails for scala 3 enum extending java Enum #464

Closed
rolman243 opened this issue Sep 28, 2022 · 5 comments
Closed

coverage compilation fails for scala 3 enum extending java Enum #464

rolman243 opened this issue Sep 28, 2022 · 5 comments

Comments

@rolman243
Copy link

rolman243 commented Sep 28, 2022

scoverage version: 2.0.4
scala versoin: 3.2.0
sbt version: 1.7.1

The following code fails to compile with sbt clean coverage test but compiles fine with sbt clean compile test

import scribe.Level

enum MetricLogLevel(val level: Level) extends Enum[MetricLogLevel]:
  case Warn  extends MetricLogLevel(Level.Warn)
  case Error extends MetricLogLevel(Level.Error)
  case Fatal extends MetricLogLevel(Level.Fatal)

Compiler failure:

[error]   |enum MetricLogLevel(val level: Level) extends Enum[MetricLogLevel]:
[error]   |                                              ^^^^^^^^^^^^^^^^^^^^
[error]   |wrong number of arguments at constructors for (_$name: String, _$ordinal: Int): Enum: (MetricLogLevel.super.<init> : (_$name: String, _$ordinal: Int): Enum), expected: 2, found: 0

[error]   |  case Warn  extends MetricLogLevel(Level.Warn)
[error]   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]   |wrong number of arguments at constructors for (level: scribe.Level, _$name: String, _$ordinal: Int): 
[error]   |  fdn.core.log.MetricLogLevel: ($anon.super.<init> : 
[error]   |  (level: scribe.Level, _$name: String, _$ordinal: Int): 
[error]   |    fdn.core.log.MetricLogLevel
[error]   |), expected: 3, found: 1

[error]   |  case Error extends MetricLogLevel(Level.Error)
[error]   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]   |wrong number of arguments at constructors for (level: scribe.Level, _$name: String, _$ordinal: Int): 
[error]   |  fdn.core.log.MetricLogLevel: ($anon.super.<init> : 
[error]   |  (level: scribe.Level, _$name: String, _$ordinal: Int): 
[error]   |    fdn.core.log.MetricLogLevel
[error]   |), expected: 3, found: 1

[error]   |  case Fatal extends MetricLogLevel(Level.Fatal)
[error]   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]   |wrong number of arguments at constructors for (level: scribe.Level, _$name: String, _$ordinal: Int): 
[error]   |  fdn.core.log.MetricLogLevel: ($anon.super.<init> : 
[error]   |  (level: scribe.Level, _$name: String, _$ordinal: Int): 
[error]   |    fdn.core.log.MetricLogLevel
[error]   |), expected: 3, found: 1

The documentation for constructor of the abstract java Enum class states:

    /**
     * Sole constructor.  Programmers cannot invoke this constructor.
     * It is for use by code emitted by the compiler in response to
     * enum class declarations.
     *
     * @param name - The name of this enum constant, which is the identifier
     *               used to declare it.
     * @param ordinal - The ordinal of this enumeration constant (its position
     *         in the enum declaration, where the initial constant is assigned
     *         an ordinal of zero).
     */
    protected Enum(String name, int ordinal) {
        this.name = name;
        this.ordinal = ordinal;
    }
@ckipp01
Copy link
Member

ckipp01 commented Sep 28, 2022

Hey @rolman243 thanks for the report. sbt-scoverage is just a thin wrapper facilitation everything. For Scala 3 the coverage logic is actually included in the compiler. Could you report this there?

@rolman243
Copy link
Author

rolman243 commented Sep 30, 2022

@ckipp01 yes of course, I'll open an issue

@TheElectronWill
Copy link

thanks for the issue!

@TheElectronWill
Copy link

this is fixed in dotty >= 3.2.2-RC1 :)

@rolman243
Copy link
Author

works with dotty 3.2.2

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