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

Regression in typer when copying case class with generic parameters #15154

Closed
WojciechMazur opened this issue May 10, 2022 · 2 comments · Fixed by #16005
Closed

Regression in typer when copying case class with generic parameters #15154

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

Comments

@WojciechMazur
Copy link
Contributor

WojciechMazur commented May 10, 2022

Compiler version

Fails since 3.1.2

Minimized code

Minimized using scala-cli

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

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

trait RType
trait TypeEntry{
  def typeAdapter: TypeAdapter[_] = ???
}

trait TypeAdapter[E]
case class OptionTypeAdapter[E](nullIsNone: Boolean, valueTypeAdapter: TypeAdapter[E]) extends TypeAdapter[E]
case class JavaOptionalTypeAdapter[E](nullIsNone: Boolean, valueTypeAdapter: TypeAdapter[E]) extends TypeAdapter[E]

def typeAdapterOf(concreteType: RType): TypeAdapter[_] = ???

@main def test() = {
  // https://github.com/gzoller/scalajack/blob/4a29366e28fbd594d7c21b4eb969ca14626ac0d1/core/src/main/scala/co.blocke.scalajack/typeadapter/TupleTypeAdapter.scala#L21-L30
  val seq = List.empty[RType]
  seq map { f =>
    typeAdapterOf(f) match {
      case ota: OptionTypeAdapter[_] => ota.copy(nullIsNone = true)
      case jota: JavaOptionalTypeAdapter[_] => jota.copy(nullIsNone = true)
      case other => other 
    }
  }
}
    

Output

[error] ./test.scala:21:41: Found:    TypeAdapter[_]
[error] Required: TypeAdapter[(avoid)E]
[error] 
[error] where:    (avoid)E is a type variable
[error]       case ota: OptionTypeAdapter[_] => ota.copy(nullIsNone = true)//.asInstanceOf[OptionTypeAdapter[_]]
[error]                                         ^^^^^^^^
[error] ./test.scala:22:48: Found:    TypeAdapter[_]
[error] Required: TypeAdapter[(avoid)E]
[error] 
[error] where:    (avoid)E is a type variable
[error]       case jota: JavaOptionalTypeAdapter[_] => jota.copy(nullIsNone = true)//.asInstanceOf[JavaOptionalTypeAdapter[_]]
[error]                                                ^^^^^^^^^```

Expectation

Should compile like in the Scala 3.1.1 or earlier
Should not need explicit casting of copy result to satisfy compiler

@WojciechMazur WojciechMazur added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels May 10, 2022
@nicolasstucki nicolasstucki added 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 10, 2022
@nicolasstucki nicolasstucki added this to the 3.2.0-RC1 milestone May 10, 2022
@nicolasstucki
Copy link
Contributor

This issue started in 3ab18a9.

@smarter
Copy link
Member

smarter commented May 16, 2022

This looks like the same problematic code pattern as SnippetChecker.scala mentioned in the commit message of 3ab18a9, so the same workaround applies: pass an explicit type argument to map:

  seq.map[TypeAdapter[?]]{ f =>
    typeAdapterOf(f) match {
      case ota: OptionTypeAdapter[_] => ota.copy(nullIsNone = true)
      case jota: JavaOptionalTypeAdapter[_] => jota.copy(nullIsNone = true)
      case other => other 
    }
  }

Closing, since there is no plan to fix this so far.

@smarter smarter closed this as completed May 16, 2022
@Kordyjan Kordyjan removed this from the 3.1.3 milestone May 31, 2022
odersky added a commit to dotty-staging/dotty that referenced this issue Sep 9, 2022
This now works with level checking on instantiation

Fixes scala#15154
odersky added a commit that referenced this issue Sep 9, 2022
This now works with level checking on instantiation

Fixes #15154
mpollmeier pushed a commit to mpollmeier/dotty that referenced this issue Oct 16, 2022
This now works with level checking on instantiation

Fixes scala#15154
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

4 participants