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

Type matched class cannot be referenced using classOf #15155

Closed
WojciechMazur opened this issue May 10, 2022 · 6 comments · Fixed by #15218
Closed

Type matched class cannot be referenced using classOf #15155

WojciechMazur opened this issue May 10, 2022 · 6 comments · Fixed by #15218
Assignees
Labels
area:typer itype:bug regression This worked in a previous version but doesn't anymore
Milestone

Comments

@WojciechMazur
Copy link
Contributor

WojciechMazur commented May 10, 2022

Compiler version

3.2.0-RC1-bin-20220429-400427d-NIGHTLY

Works with 3.1.2

The first bad commit is 54dc0c1 from #14761

Minimized code

//> using scala "3.2.0-RC1-bin-20220429-400427d-NIGHTLY"

// Last working version
// //> using scala "3.1.2"

import scala.reflect.ClassTag
// https://github.com/json4s/json4s/blob/355d8751391773e0d79d04402a4f9fb7bfc684ec/ext/src/main/scala-3/org/json4s/ext/package.scala#L4-L8
type Aux[A] = { type Value = A }
type EnumValue[A <: Enumeration] = A match {
  case Aux[a] => a
}

// https://github.com/json4s/json4s/blob/355d8751391773e0d79d04402a4f9fb7bfc684ec/ext/src/main/scala/org/json4s/ext/EnumSerializer.scala#L25-L26
class EnumSerializer[E <: Enumeration: ClassTag](enumeration: E) {
  val EnumerationClass = classOf[EnumValue[E]]
}

Output

[error] ./test.scala:15:34: EnumValue[E] is not a class type
[error]   val EnumerationClass = classOf[EnumValue[E]]
[error]                                  ^^^^^^^^^^^^```

Expectation

Should correctly allow getting an instance of Class for Enum.Value

@WojciechMazur WojciechMazur added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels May 10, 2022
@prolativ prolativ added area:typer regression This worked in a previous version but doesn't anymore and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels May 11, 2022
@Kordyjan Kordyjan added this to the 3.1.3 milestone May 16, 2022
@nicolasstucki
Copy link
Contributor

nicolasstucki commented May 17, 2022

The first bad commit is 54dc0c1 from #14761

@griggt
Copy link
Collaborator

griggt commented May 17, 2022

The first bad commit is 54dc0c1 from #14761

Hmm, that commit shows as good for me. I bisected it to d1957e5 from #13780.

@odersky
Copy link
Contributor

odersky commented May 18, 2022

It looks indeed plausible that #13780 is the PR that makes it fail.

I added a summon[EnumValue[A]] and got:

Note: a match type could not be fully reduced:
   |
   |  trying to reduce  EnumValue[E]
   |  failed since selector  E
   |  does not match  case Aux[a] => a
   |  and cannot be shown to be disjoint from it either.

@odersky
Copy link
Contributor

odersky commented May 18, 2022

I am not sure the match type is supposed to reduce. Maybe use a TypeTest? But I don't know enough about the details here.

@odersky
Copy link
Contributor

odersky commented May 18, 2022

@OlivierBlanvillain, do you have an opinion about this issue?

@OlivierBlanvillain
Copy link
Contributor

I am not sure the match type is supposed to reduce.

I'm also not sure. This code is asking the compiler to show that E <: Aux[a], knowing that E <: Enumeration and type Aux[A] = { type Value = A }. Looking at the definitions, Value is an abstract inner class of Enumeration, so it feels like E could be a subtype of the { type Value = A } refinement, but I don't know how those two features interact (inner classes vs refinement types)...

@Kordyjan Kordyjan removed this from the 3.1.3 milestone May 24, 2022
odersky added a commit to dotty-staging/dotty that referenced this issue May 26, 2022
bishabosha pushed a commit to dotty-staging/dotty that referenced this issue Oct 18, 2022
@Kordyjan Kordyjan added this to the 3.2.0 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:typer itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants