-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #7249: Search for hidden givens only at whole type #7300
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
Conversation
This fixes also #7248 |
tests/pos/i7250.scala
Outdated
|
||
inline given f[T <: Foo]: T = inline erasedValue[T] match | ||
case _: A => new A{}.asInstanceOf[T] | ||
case _: B[a] => summon[a].asInstanceOf[T] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This summon shouldn't succeed though on compile time. Starting from println
:
// 1) initial call
f[B[Int]]
// 2) inlining `f`
inline erasedValue[B[Int]] match
case _: A => new A{}.asInstanceOf[B[Int]]
case _: B[a] => summon[a].asInstanceOf[B[Int]]
// 3) second case matched and inlined with a = Int
summon[Int].asInstanceOf[B[Int]]
summon[Int]
should fail since there's no Int
given in scope, shouldn't it?
scala> summon[Int]
1 |summon[Int]
| ^
|no implicit argument of type Int was found for parameter x of method summon in object DottyPredef
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if it tries Int & Foo
it still won't find anything suitable, since f
returns T <: Foo
and nothing about it says that it is an intersection with Int
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It actually tries f[Nothing]
and succeeds with the A
case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I remember testing it with inline given f[T >: Nothing <: Foo]: T
, and it still finds f
when looking for Nothing
(as understood from the unchanged behaviour in that case).
Don't try to find a hidden implicit for a part of type type that was searched for, unless that part is fully defined. The reason is that any type variables in a subtype might be associated with constraints that are lost at the point of issuing a the hidden givens addendum. The commit also contains a tweak to "isFullyDefined" which makes an uninstantiated type variable that is not bound in the current constraint count as "not fully defined", where previously it was "fully defined".
The test should have been a run test but it is unclear whether we can make it run correctly
Don't try to find a hidden implicit for a part of type type that
was searched for, unless that part is fully defined.
The reason is that any type variables in a subtype might be associated
with constraints that are lost at the point of issuing a "hidden
givens" addendum.
The commit also contains a tweak to "isFullyDefined" which makes
an uninstantiated type variable that is not bound in the current
constraint count as "not fully defined", where previously it was
"fully defined".