-
Notifications
You must be signed in to change notification settings - Fork 1.1k
top level extension method dealiases opaque type in result type #18097
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
Comments
so for some reason PositiveNumber is being de-aliased to def multMap2[A >: Nothing <: Any](x: Map[A, PositiveNumber],
num: PositiveNumber): Map[A, PositiveNumber] =
x.map[A, Double](
{
def $anonfun(x$1: (A, PositiveNumber)): (A, Double) =
{
val key: A = x$1._1
val value: PositiveNumber = x$1._2
ArrowAssoc[A](key).->[Double](mult2(value)(num))
}
closure($anonfun)
}
).toMap[A, PositiveNumber](
/* missing */summon[(A, Double) <:< (A, PositiveNumber)])
def multMap2_2[A >: Nothing <: Any](x: Map[A, PositiveNumber],
num: PositiveNumber): Map[A, PositiveNumber] =
x.map[A, PositiveNumber](
{
def $anonfun(x$1: (A, PositiveNumber)): (A, PositiveNumber) =
{
val key: A = x$1._1
val value: PositiveNumber = x$1._2
ArrowAssoc[A](key).->[PositiveNumber](mult2(value)(num))
}
closure($anonfun)
}
).toMap[A, PositiveNumber](<:<.refl[(A, PositiveNumber)]) |
This needs a minimization to be sure, right now there is way too much type inference going on for a good diagnosis. |
I think I have a simpler reproducer for the same issue: https://scastie.scala-lang.org/YRmAX35aTyO8mEoIM1kgRw this only happens if the extensions method has the same name as native method on the wrapped type. Everything works fine if we move it to the |
I am also seeing this problem with 3.3.1, 3.3.2-RC2, 3.4.0-RC1 This is my minimization. Opaque class: package test
type Foo = Unit
val bar: Foo = ()
//object Foo {
opaque type Opaque = Unit
extension (foo: Foo)
def go: Option[Opaque] = ???
//} Test class: package test
//import Foo.*
final case class Test(value: Opaque)
def test: Test =
//go(bar) match
bar.go match
case Some(value) => Test(value)
case _ => ??? Incorrect compiler error:
The above includes 2 different (commented out) workarounds:
|
NOTE: I originally saw this problem in a slightly different context. But I assume it is the same? My extension method was returning an anonymous tuple inside an Option. Option[(Opaque, A)] here a third workaround was to use a case class instead of the tuple Option[Result[A]]
// with
final case class Result[A](value: Opaque, a: A) Is this because the opaque type is not explicitly mentioned in the return type? |
Compiler version
3.3.0
Minimized code
Output
Expectation
I would expect both functions be defined without type error. For some reason, when an opaque type is not a top-level definition, there is no type error when defining these functions.
The text was updated successfully, but these errors were encountered: