Skip to content
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

Better comparisons for type projections #17092

Merged
merged 3 commits into from
Mar 25, 2023
Merged

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Mar 12, 2023

We already implemented in essence the rule suggested in lampepfl/dotty-feature-requests#14:

Γ ⊨ p : T
------------------------ (Sel-<:-Proj)
Γ ⊨ p.A <: T#A

This rule is implemented in isSubPrefix. But we did not get to check that since we concluded prematurely that an alias type would never match. The alias type in question in i17064.scala was

Outer#Inner

Since Outer is not a path, the asSeenFrom to recover the info of Outer#Inner got approximated with a Nothing argument and therefore the alias failed. It is important in this case that we could still succeed with a isSubPrefix test, which comes later. So we should not return false when the prefix is not a singleton.

Fixes #17064

We already implemented in essence the rule suggested in lampepfl/dotty-feature-requests#14:

```
Γ ⊨ p : T
------------------------ (Sel-<:-Proj)
Γ ⊨ p.A <: T#A
```

This rule is implemented in `isSubPrefix`. But we did not get to check that since we concluded prematurely that
an alias type would never match. The alias type in question in i17064.scala was

```scala
Outer#Inner
```
Since `Outer` is not a path, the asSeenFrom to recover the info of `Outer#Inner this got approximated with
a `Nothing` argument and therefore the alias failed. It is important in this case that we could still succeed
with a `isSubPrefix` test, which comes later. So we should not return `false` when the prefix is not a singleton.

Fixes scala#17064
Copy link
Member

@smarter smarter left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM.

Comment on lines 292 to 293
def hasPrecisePrefix(tp: NamedType) =
tp.prefix.isSingleton || tp.prefix == NoPrefix
Copy link
Member

Choose a reason for hiding this comment

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

This seems fine, but since asSeenFrom itself uses TypeOps.isLegalPrefix for this purpose, wouldn't it make sense to also use it here to ensure the checks stay aligned?

@smarter smarter assigned odersky and unassigned smarter Mar 13, 2023
* See pos/i17064.scala for a test case
*/
def hasStablePrefix(tp: NamedType) =
tp.prefix.isStable
Copy link
Member

Choose a reason for hiding this comment

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

I dropped the NoPrefix check since it's already implied by isStable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes, I overlooked that.

@odersky odersky merged commit dcf5f9d into scala:main Mar 25, 2023
@odersky odersky deleted the fix-17064 branch March 25, 2023 18:29
@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.

a path dependent type does not conform to its projection type
3 participants