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

Throw a type error when using hk-types in unions or intersections #16712

Merged
merged 3 commits into from
Jan 18, 2023

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Jan 17, 2023

Throw a type error instead of crashing when using higher-kinded types in unions or intersections.

We check kindedness only in PostTyper (to avoid cycles), which means we might get into situations where we combine a higher-kinded type in a union or intersection, which is illegal. In this case we now diagnose the problem with a TypeError instead of failing an assert. However, after Typer we do fail since by then such situations should have been checked by then.

Fixes #16696

Throw a type error instead of crashing when using higher-kinded types in unions or intersections.

We check kindedness only in PostTyper (to avoid cycles), which means we might get into situations
where we coming a higher-kinded type in a union or intersection, which is illegal. In this case
we now diagnose the problem with a TypeError instead of failing an assert. However, after Typer
we do fail since by then such situations should have been checked by then.

Fixeds scala#16696
Copy link
Member

@dwijnand dwijnand left a comment

Choose a reason for hiding this comment

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

LGTM

tests/new/test.scala Outdated Show resolved Hide resolved
-- Error: tests/neg/i16696.scala:20:27 ---------------------------------------------------------------------------------
20 | val boom = BoxMaker[Foo].make(_.foo) // error
| ^
| test2.Foo is not a value type, cannot be used in in intersection R & test2.Foo
Copy link
Member

Choose a reason for hiding this comment

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

actually, it reads "in in"

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. Good that you spotted! it!

@odersky odersky merged commit b824375 into scala:main Jan 18, 2023
@odersky odersky deleted the fix-16696 branch January 18, 2023 10:15
@Kordyjan Kordyjan added this to the 3.3.0 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.

Union and intersection types are not causing checking the kind of type parameters
3 participants