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

Pattern binding using abstract type unapply gets wider type when @unchecked #14821

Closed
griggt opened this issue Apr 1, 2022 · 1 comment · Fixed by #14898
Closed

Pattern binding using abstract type unapply gets wider type when @unchecked #14821

griggt opened this issue Apr 1, 2022 · 1 comment · Fixed by #14898
Assignees
Milestone

Comments

@griggt
Copy link
Contributor

griggt commented Apr 1, 2022

Compiler version

3.1.2-RC3 and 3.1.3-RC1-bin-SNAPSHOT-git-616308d

Minimized code

trait Statement
trait Definition extends Statement

trait ClassDef extends Definition:
  def constructor: DefDef

object ClassDef:
  def copy(constr: DefDef): ClassDef = ???

// >>> This abstract implementation of DefDef causes a compilation error in transform...
type DefDef <: Definition
val DefDef: DefDefModule = ???
trait DefDefModule:
  def unapply(ddef: DefDef): (String, List[AnyRef])
// ...unless this given TypeTest is commented out, in which case we get only a type test warning
given scala.reflect.TypeTest[Statement, DefDef] = ???

// >>> This alternative works
// trait DefDef extends Definition
// object DefDef:
//   def unapply(ddef: DefDef): (String, List[AnyRef]) = ???

// >>> This alternative also works
// case class DefDef(name: String, paramss: List[AnyRef]) extends Definition

def transform(tree: Statement): Statement = tree match
  case tree: ClassDef =>
    val constructor @ DefDef(_, _) = transform(tree.constructor): @unchecked
    ClassDef.copy(constructor)

Output

-- [E007] Type Mismatch Error: test.scala:29:18 -----------------------------------------------
29 |    ClassDef.copy(constructor)
   |                  ^^^^^^^^^^^
   |                  Found:    (constructor : Statement)
   |                  Required: DefDef
   |
   | longer explanation available when compiling with `-explain`

Expectation

Without the @unchecked annotation, constructor is typed as DefDef, I expected the same here.
It compiles without the TypeTest given (but emits a type test warning instead).

Context: this arose while rebasing #14294 on latest main; @unchecked was added (as per advice) to

https://github.com/lampepfl/dotty/blob/616308d34912f1a42bee256bf77b85db3194c46b/library/src/scala/quoted/Quotes.scala#L4716

to suppress the refutable pattern warning, but instead caused the above error and a failure to bootstrap.

@griggt griggt added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 1, 2022
@KacperFKorban KacperFKorban added area:typer and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 1, 2022
@odersky
Copy link
Contributor

odersky commented Apr 3, 2022

It seems to be related to TypeTest's logic.

griggt added a commit to griggt/dotty that referenced this issue Apr 6, 2022
griggt added a commit to griggt/dotty that referenced this issue Apr 7, 2022
griggt added a commit to dotty-staging/dotty that referenced this issue Apr 10, 2022
griggt added a commit to griggt/dotty that referenced this issue Apr 16, 2022
griggt added a commit to griggt/dotty that referenced this issue Apr 17, 2022
griggt added a commit to griggt/dotty that referenced this issue Apr 17, 2022
griggt added a commit to griggt/dotty that referenced this issue Apr 17, 2022
griggt added a commit to griggt/dotty that referenced this issue Apr 17, 2022
griggt added a commit to griggt/dotty that referenced this issue Apr 20, 2022
michelou pushed a commit to michelou/dotty that referenced this issue Apr 25, 2022
griggt added a commit to griggt/dotty that referenced this issue May 10, 2022
griggt added a commit to griggt/dotty that referenced this issue May 11, 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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants