Skip to content

Fix #3343: Make baseType work properly with type lambdas #3345

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
Oct 19, 2017

Conversation

smarter
Copy link
Member

@smarter smarter commented Oct 17, 2017

Previously,

    `C[Char]`.baseTypeOf(`Traversable[Char]`)
    where C := `[X] => List[X]`

returned Traversable[ParamRef(A)] instead of Traversable[Char],
because the substitution was done on the type parameters of the class
symbol instead of the type parameters of the type, these are different
when type lambdas are involved.

val tparams = clsd.typeParams
if (tparams.hasSameLengthAs(args)) baseTypeOf(tycon).subst(tparams, args)
else NoType
baseTypeOf(tycon).substTypeParams(tycon, args)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the real fault is the condition. It was meant to check that we have an application of a class instead of a type lambda but failed at that. So I'd fix that first. One candidate is the condition of substTypeParams, that the typeParams of subsym are symbols. If that's the case, proceed as before, if not do a baseTypeOf(superType), again as before.

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense. PR updated.

Previously,
    `C[Char]`.baseTypeOf(`Traversable[Char]`)
    where C := `[X] => List[X]`
returned `Traversable[ParamRef(A)]` instead of `Traversable[Char]`,
because the substitution was done on the type parameters of the class
symbol instead of the type parameters of the type, these are different
when type lambdas are involved. This is fixed by always going through
`AppliedType#superType` when the tycon is not a class.
@allanrenucci
Copy link
Contributor

I can confirm it fixes the issue I reported from scalacheck

@smarter smarter dismissed odersky’s stale review October 18, 2017 13:51

Comment addressed.

Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

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

LGTM

@allanrenucci allanrenucci merged commit 174444d into scala:master Oct 19, 2017
@allanrenucci allanrenucci deleted the fix-3343 branch October 24, 2017 11:37
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