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

Check bounds in match type case bodies #17602

Closed
wants to merge 7 commits into from

Conversation

dwijnand
Copy link
Member

@dwijnand dwijnand commented May 26, 2023

Fixes #13741

@dwijnand dwijnand force-pushed the match-type-check-bounds branch from 84365e8 to a1eb832 Compare May 26, 2023 18:13
@dwijnand dwijnand force-pushed the match-type-check-bounds branch from 00957b5 to 23e00c3 Compare June 6, 2023 18:09
@dwijnand dwijnand force-pushed the match-type-check-bounds branch 2 times, most recently from 1a849d6 to 6642d65 Compare October 6, 2023 13:04
@dwijnand dwijnand marked this pull request as ready for review October 12, 2023 17:11
@dwijnand dwijnand marked this pull request as draft October 12, 2023 17:11
@dwijnand dwijnand force-pushed the match-type-check-bounds branch from 75e7c41 to 538a8bd Compare October 15, 2023 21:02
@dwijnand dwijnand marked this pull request as ready for review October 16, 2023 14:09
@dwijnand dwijnand requested a review from sjrd October 16, 2023 14:09
@dwijnand dwijnand assigned sjrd and unassigned dwijnand Oct 16, 2023
@dwijnand
Copy link
Member Author

@sjrd will you review if I rebase this? 😄

@sjrd
Copy link
Member

sjrd commented Feb 23, 2024

Oh yes, sorry.

@dwijnand dwijnand force-pushed the match-type-check-bounds branch from b97343a to 76c8268 Compare February 23, 2024 10:33
@dwijnand dwijnand marked this pull request as draft February 23, 2024 10:33
@@ -21,6 +21,7 @@ object TypeEval:
case tp: TypeProxy =>
val tp1 = tp.superType
if tp1.isStable then tp1.fixForEvaluation else tp
case AndType(tp1: ConstantType, tp2) if tp1.frozen_<:<(tp2) => tp1
Copy link
Member

Choose a reason for hiding this comment

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

AndType is supposed to be commutative, so if we do this we must also do the mirror:

Suggested change
case AndType(tp1: ConstantType, tp2) if tp1.frozen_<:<(tp2) => tp1
case AndType(tp1: ConstantType, tp2) if tp1.frozen_<:<(tp2) => tp1
case AndType(tp1, tp2: ConstantType) if tp2.frozen_<:<(tp1) => tp2

withMode(Mode.Pattern)(super.transform(x)).asInstanceOf[CaseDef]
def transformCase(x: CaseDef): CaseDef =
val gadtCtx = x.pat.removeAttachment(typer.Typer.InferredGadtConstraints) match
case Some(gadt) => ctx.fresh.setGadtState(GadtState(gadt))
Copy link
Member

Choose a reason for hiding this comment

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

Is this enough to ensure that, after PostTyper, the trees are well-kinded without resorting to GADT reasoning? I'm not familiar with what are the consequences of doing setGadtState.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not inserting any casts, if that's what you're asking. And I'm hoping we can handle things like:

class Foo
class Bar
class Res[X <: Bar]
type MT[X <: Foo | Bar] = X match
  case Foo => Unit
  case Bar => Res[X] // X vs bounds check <: Bar 

in part also because I've found adding a type intersection (for types) doesn't fix errors like adding a type casting (for terms) fixes errors...

Copy link
Member Author

@dwijnand dwijnand Feb 28, 2024

Choose a reason for hiding this comment

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

So we can either:

  1. disallow such reasoning, force users to insert type intersections, and then decide how much to work on the limitations of those intersections
  2. allow these things to require GADT reasoning
  3. deal with how to force types to honour bounds, and perhaps in a way that is accessible to users too
  4. return to the AssumeInfo tree idea

😭

@sjrd sjrd assigned dwijnand and unassigned sjrd Feb 27, 2024
@dwijnand dwijnand closed this Sep 25, 2024
@dwijnand dwijnand deleted the match-type-check-bounds branch September 25, 2024 22:30
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.

Match type does not check bounds
2 participants