Skip to content

AppliedTypes returned by baseType shouldn't have type lambdas as constructors #17071

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

Merged
merged 1 commit into from
Mar 16, 2023

Conversation

dwijnand
Copy link
Member

@dwijnand dwijnand commented Mar 8, 2023

AppliedTypes returned by baseType shouldn't have type lambdas as constructors

In tests/pos/argDenot-alpakka.min.scala, we want

`(([O] =>> Foo[O, S]) @uV)[Int]`.baseType(`Foo`)

to return Foo[Int] rather than an applied type lambda, so that we can rely on
the invariant that the type arguments of the type returned by baseType(cls)
correspond to the type parameter of cls which NamedType#argDenot is implicitly
relying on.

This could be achieved by removing the initial if branch from the AppliedType
case in baseTypeOf, since the recursive fallback will always work, but it makes
sense to keep a special case for performance, so we just explicitly add as a
condition to the fast-path that the type constructor of the AppliedType can't be
a lambda.

@dwijnand dwijnand marked this pull request as ready for review March 8, 2023 20:59
@dwijnand dwijnand requested a review from smarter March 8, 2023 20:59
@smarter
Copy link
Member

smarter commented Mar 8, 2023

I went with fixing the input before baseType - the alternative would be
to make baseType do the same type constructor dealiasWidening.

Does anything go wrong if we change baseType instead? Intuitively I would expect it to always return an AppliedType(Foo, ...).

@dwijnand
Copy link
Member Author

dwijnand commented Mar 8, 2023

Let's see what all of CI says. WDYT of doing it like this?

@smarter
Copy link
Member

smarter commented Mar 14, 2023

WDYT of doing it like this?

I think this is the right place to fix this, but I wasn't a fan of having a slightly different typeSymbol, so I pushed a commit with a different approach where I explicitly check the shape of the type constructor.

@smarter
Copy link
Member

smarter commented Mar 15, 2023

@dwijnand if this looks good to you I can squash and merge.

@dwijnand dwijnand force-pushed the alpakka-argDenot branch 2 times, most recently from 9728430 to 69b0151 Compare March 15, 2023 18:36
@dwijnand dwijnand changed the title Fix argDenot, widenDealias before baseType, to get the right type arguments AppliedTypes returned by baseType shouldn't have type lambdas as constructors Mar 15, 2023
@dwijnand
Copy link
Member Author

Can't approve my own PR. Feel free to force push if you want and merge. Thanks, Guillaume.

…tructors

In tests/pos/argDenot-alpakka.min.scala, we want

    `(([O] =>> Foo[O, S]) @UV)[Int]`.baseType(`Foo`)

to return `Foo[Int]` rather than an applied type lambda, so that we can rely on
the invariant that the type arguments of the type returned by baseType(cls)
correspond to the type parameter of cls which `NamedType#argDenot` is implicitly
relying on.

This could be achieved by removing the initial if branch from the AppliedType
case in baseTypeOf, since the recursive fallback will always work, but it makes
sense to keep a special case for performance, so we just explicitly add as a
condition to the fast-path that the type constructor of the AppliedType can't be
a lambda.
@smarter smarter merged commit 2dec682 into scala:main Mar 16, 2023
@dwijnand dwijnand deleted the alpakka-argDenot branch March 16, 2023 15:09
@Kordyjan Kordyjan added this to the 3.3.1 milestone Aug 1, 2023
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.

3 participants