Skip to content

Allow poly-kinded GADT vars to infer constraints #19916

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

Closed
wants to merge 1 commit into from

Conversation

dwijnand
Copy link
Member

Allowing the types to flow through in thirdTryNamed requires a tweak to
baseType. Given class C[T <: Int] (from tests/pos-macros/i10864a) the
basetype of a TypeRef of just "C", with the Any class symbol, shouldn't
return Any because "C" is not a proper/value type. That is, in
baseType, we need to short-circuit TypeProxy.superType (i.e.
underlying), which is returns resultType for a HKLambda.

Fixes #19904

Allowing the types to flow through in thirdTryNamed requires a tweak to
baseType.  Given "class C[T <: Int]" (from tests/pos-macros/i10864a) the
basetype of a TypeRef of just "C", with the Any class symbol, shouldn't
return Any because "C" is not a proper/value type.  That is, in
baseType, we need to short-circuit TypeProxy.superType (i.e.
underlying), which is returns resultType for a HKLambda.
@dwijnand
Copy link
Member Author

With this change, when typing y match { case Bx[b] => Unit }], when we constrain Bx[b] against y, we correctly infer the b goes from <: AnyKind to <: Any. With that, when we get to checkOverride in RefChecks, we end up with Any <:< Any for the lambda param infos.

@dwijnand dwijnand marked this pull request as ready for review March 12, 2024 11:52
@dwijnand dwijnand requested a review from sjrd March 12, 2024 11:53
Comment on lines +583 to 586
if tp1.hasSimpleKind then
if cls2 eq AnyClass then return true
if cls2 == defn.SingletonClass && tp1.isStable then return true
return tryBaseType(cls2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this change actually necessary? Isn't tryBaseType always going to fail anyway when tp1.hasSimpleKind is false? (given that you added the case HKTypeLambda => false in baseType, which makes sense)

Copy link
Member Author

@dwijnand dwijnand Mar 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because then it cascades to more "tries", including allowing a gadt variable bounded by AnyKind inferring a gadt bound.

@sjrd
Copy link
Member

sjrd commented Mar 12, 2024

That is, in baseType, we need to short-circuit TypeProxy.superType (i.e. underlying), which is returns resultType for a HKLambda.

I have always found dubious that HKTypeLambda.superType returns Any. Would we solve this issue if we made it return AnyKind instead?

@dwijnand
Copy link
Member Author

That is, in baseType, we need to short-circuit TypeProxy.superType (i.e. underlying), which is returns resultType for a HKLambda.

I have always found dubious that HKTypeLambda.superType returns Any. Would we solve this issue if we made it return AnyKind instead?

Not sure. And I wouldn't be surprised it's a battle to make that change. But we can try.

@dwijnand
Copy link
Member Author

dwijnand commented Jul 9, 2024

That is, in baseType, we need to short-circuit TypeProxy.superType (i.e. underlying), which is returns resultType for a HKLambda.

I have always found dubious that HKTypeLambda.superType returns Any. Would we solve this issue if we made it return AnyKind instead?

Not sure. And I wouldn't be surprised it's a battle to make that change. But we can try.

Tried and it was as battle, so I gave up.

@dwijnand dwijnand closed this Sep 25, 2024
@dwijnand dwijnand deleted the binding-ub-AnyKind branch September 25, 2024 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Match type forgets kindness of variable extending wildcarded trait
2 participants