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

Recent regression in interaction between match types and implicit conversion under separate compilation #20136

Closed
smarter opened this issue Apr 9, 2024 · 0 comments · Fixed by #20147
Assignees
Labels
area:implicits related to implicits area:match-types itype:bug regression This worked in a previous version but doesn't anymore
Milestone

Comments

@smarter
Copy link
Member

smarter commented Apr 9, 2024

Compiler version

This broke after #19871 was merged. It works in d2a6392

Minimized code

A_1.scala:

package a

trait Expr:
  type Value
object Expr:
  type Of[V] = Expr { type Value = V }
  type ExtractValue[E <: Expr] = E match
    case Expr.Of[v] => v

B_2.scala

package a

trait TC[E <: Expr]:
  type Elem = Expr.ExtractValue[E]
class BIExpr extends Expr:
  type Value = BigInt
class Foo extends TC[BIExpr]:
  val v: Elem = 0

Output

> scalac A_1.scala B_2.scala -d join_out
> scalac A_1.scala -d a_out
> scalac B_2.scala -classpath a_out -d b_out
-- [E007] Type Mismatch Error: B_2.scala:8:16
8 |  val v: Elem = 0
  |                ^
  |                Found:    (0 : Int)
  |                Required: Foo.this.Elem
  |
  |                The following import might fix the problem:
  |
  |                  import scala.math.BigInt.int2bigInt
  |

Expectation

Join and separate compilation should both compile.

@smarter smarter added itype:bug area:implicits related to implicits area:match-types regression This worked in a previous version but doesn't anymore labels Apr 9, 2024
smarter added a commit to dotty-staging/dotty that referenced this issue Apr 9, 2024
This is needed for the same reason than the normalization in `computeIScope`
added by 90c3fbd.

IMO, it's already very hard to figure out where `.normalize` should be used,
but the fact that it sometimes is only needed under separate compilation is
really error-prone and leads to very hard to debug issues. Ideally we should
deal with the same types under separate and join compilation.

While I'm at it, I added one defensively in `addPath` since I can't tell
whether it is needed or not.

Fixes scala#20136.
EugeneFlesselle added a commit that referenced this issue Apr 9, 2024
Both observe different behaviours match type reductions
depending on whether they are compiled together or separately.
They both compile only with separate compilation.
EugeneFlesselle added a commit that referenced this issue Apr 9, 2024
This already wasn't the case for unpickled match types,
which caused varying results for `ImplicitRunInfo#isAnchor`,
by not reaching the `isMatchAlias` condition.

Ensures both #20071 and #20136 each have the same result,
when compiled with a classpath dependency as when merged.
Note that they both still fail (20071 compiles but shouldn't),
but at least do so consistently.

Also update TreeUnpickler MATCHtpt doc to align with changes from #19871

Co-authored-by: Guillaume Martres <[email protected]>
EugeneFlesselle added a commit to dotty-staging/dotty that referenced this issue Apr 10, 2024
odersky added a commit that referenced this issue Apr 10, 2024
Match types are already not flagged as `Deferred` when unpickled.
This caused varying results for `ImplicitRunInfo#isAnchor`, by not
reaching the `isMatchAlias` condition when created from the Namer.

Ensures both #20071 and #20136 each have the same result, when compiled
with a classpath dependency as when merged into a single file.

Fixes #20136
@Kordyjan Kordyjan added this to the 3.5.0 milestone May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:implicits related to implicits area:match-types itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
3 participants