-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Wrong type inferred with Function1 and type parameter in result type #5413
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
This can be reproduced without implicits with object Foo {
type Or[A]
def foo[A](from: A => Or[A]): Any = null
def id[A]: A => A = identity
foo(id)
} where typer produces package <empty> {
final lazy module val Foo: Foo$ = new Foo$()
final module class Foo$() extends Object(), _root_.scala.Serializable {
this: Foo.type =>
type Or[A >: Nothing <: Any] >: Nothing <: Any
def foo[A >: Nothing <: Any](from: Function1[A, Foo.Or[A]]): Any = null
def id[A >: Nothing <: Any]: Function1[A, A] =
{
def $anonfun(x: A): A = identity[A](x)
closure($anonfun)
}
Foo.foo[Foo.Or[_]](Foo.id[Foo.Or[_]])
}
} this issue is that the inferred type Though writing the inferred type explicitly does result in the correct typing error 6 | foo(id[Or[_]])
| ^^^^^^^^^
| Found: Foo.Or[_] => Foo.Or[_]
| Required: Nothing => Foo.Or[A]
|
| where: A is a type variable or -- [E007] Type Mismatch Error: Foo.scala:6:13 ----------------------------------
6 | foo[Or[_]](id)
| ^^
| Found: Nothing => Nothing
| Required: Foo.Or[_] => Foo.Or[Foo.Or[_]] This could be due to a missing constraint while inferring the type of |
It infers a weird type, which looks nevertheless type correct.
This looks more like a problem with -Ycheck to me that it cannot typecheck this corner-case. |
Fix #5413: Add regression tests
This test (loosely based on tests/pos/t2023.scala) normally compiles, but does not pass -Ycheck:all:
Output of
dotc -Ycheck:all Test.scala
:The text was updated successfully, but these errors were encountered: