Skip to content

Fix #4884: asSeenFrom on incorrect prefix in type applications #4900

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

Blaisorblade
Copy link
Contributor

@Blaisorblade Blaisorblade commented Aug 6, 2018

WIP fix #4884. PR for testing. Currently causing a stackoverflow on a benchmark, but only with the non-bootstrapped compiler; what's worse is that the stackoverflow doesn't go away when increasing stack size.

Approach

In this code we fetch the type parameter bounds from the definition, so we must
substitute their definition using asSeenFrom with the correct prefix.

The correct prefix is however hard to find: TypeApplications.typeParams finds
a self: TypeRefs (after however many steps), the correct prefix is
self.prefix.

In fact, a compositional typing rule would obtain the bounds from the type (or,
well, kind) of the type constructor; that would avoid the need for using
asSeenFrom. We only have a way to obtain such a kind for NamedType (where we
can take the info). That might be enough, but there might be another way to
fix this.

@Blaisorblade Blaisorblade self-assigned this Aug 6, 2018
@odersky
Copy link
Contributor

odersky commented Aug 7, 2018

I came across this problem independently when working on transparent functions. It's quite a subtle problem. Afters several false starts I found a fix which looks right in #4902.

@Blaisorblade Blaisorblade force-pushed the fix-4884-checkAppliedType-asSeenFrom branch from 1ae7d54 to 4890056 Compare August 7, 2018 13:17
@Blaisorblade Blaisorblade changed the title WIP Fix #4884: asSeenFrom on incorrect prefix in type applications Fix #4884: asSeenFrom on incorrect prefix in type applications Aug 7, 2018
In this code we fetch the type parameter bounds from the definition, so we must
substitute their definition using `asSeenFrom` with the correct prefix.

The correct prefix is however hard to find: `TypeApplications.typeParams` finds
a `self: TypeRefs` (after however many steps), the correct prefix is
`self.prefix`.

In fact, a compositional typing rule would obtain the bounds from the type (or,
well, kind) of the type constructor; that would avoid the need for using
`asSeenFrom`. We only have a way to obtain such a kind for `NamedType` (where we
can take the `info`). However, that seems enough.
@Blaisorblade Blaisorblade force-pushed the fix-4884-checkAppliedType-asSeenFrom branch from 4890056 to 33d1d7c Compare August 7, 2018 13:58
@Blaisorblade
Copy link
Contributor Author

Fair enough — my original fix works for Checking, but not for earlier, and your fix also uses info.typeParams on TypeRef.

@Blaisorblade Blaisorblade deleted the fix-4884-checkAppliedType-asSeenFrom branch August 8, 2018 16:02
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.

Abstract type bound of type member is forgotten?
2 participants