scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.73k stars 1.04k forks source link

Transparentness of inline defs doesn't propagate #15506

Open prolativ opened 2 years ago

prolativ commented 2 years ago

Compiler version

3.2.0-RC1

Minimized code

//> using scala "3.2.0-RC1"

class X1
class X2

transparent inline def foo: X1 | X2 =
  new X1

transparent inline def bar: (X1 | X2, X1 | X2) =  
  (foo, foo)

val x: (X1, X1) = bar

Output

[error] ./Transparent.scala:12:19: Found:    (X1 | X2, X1 | X2)
[error] Required: (X1, X1)
[error] val x: (X1, X1) = bar
[error]                   ^^^

Expectation

After inlining the type of x should be known to be (X1, X2) and the entire snippet should compile.

bishabosha commented 2 years ago

I think this is a duplicate of #8739, feel free to reopen if not

nicolasstucki commented 2 years ago

Minimized

transparent inline def foo: Int | Boolean = 2
transparent inline def bar: Option[Int | Boolean] = Some(foo)
val x: Some[Int] = bar

The issue is that we are not refining the inferred type parameter of the Some.apply method. It is similar to https://github.com/lampepfl/dotty/issues/8739.

nicolasstucki commented 2 years ago

Same issue with

transparent inline def bar(x: Int | Boolean): Option[Int | Boolean] = Some(x)
val x: Some[Int] = bar(2)

but this one has a workaround if we use Some[x.type](x)