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

Attaching Warnings discards the 'hidden part' of an intersection type #12177

Open
radeusgd opened this issue Jan 29, 2025 · 0 comments
Open

Attaching Warnings discards the 'hidden part' of an intersection type #12177

radeusgd opened this issue Jan 29, 2025 · 0 comments
Assignees
Labels

Comments

@radeusgd
Copy link
Member

As requested by @JaroslavTulach, reporting this as a separate issue.

Whenever an intersection type A & B is cast to A (hiding the B part), the B part should still be possible to be uncovered by a cast. However attaching a warning to a value makes it impossible to do so.

We already have pending tests demonstrating the issue:

group_builder.specify "attaching warnings to an intersection type should not lose even the hidden refinements" pending=dispatch_pending <|
ab = make_a_and_b
x = ab:A
x_with_warning = Warning.attach (Illegal_State.Error "my warning") x
y = x_with_warning:(A & B)
y.is_a A . should_be_true
y.is_a B . should_be_true
y.a_method . should_equal "A method"
y.b_method . should_equal "B method"
Problems.expect_only_warning Illegal_State y
group_builder.specify "removing warnings from an intersection type should not lose even the hidden refinements" pending=dispatch_pending <|
ab = make_a_and_b
x1 = Warning.attach (Illegal_State.Error "my warning") (ab:A)
x2 = (Warning.attach (Illegal_State.Error "my warning") ab):A
x1_without_warning = x1.remove_warnings
x2_without_warning = x2.remove_warnings
r1 = x1_without_warning:(A & B)
r2 = x2_without_warning:(A & B)
Problems.assume_no_problems r1
r1.is_a A . should_be_true
r1.is_a B . should_be_true
r1.a_method . should_equal "A method"
r2.b_method . should_equal "B method"
Problems.assume_no_problems r2
r2.is_a A . should_be_true
r2.is_a B . should_be_true
r2.a_method . should_equal "A method"
r2.b_method . should_equal "B method"
r3 = (ab:A).remove_warnings:(A & B)
r3.is_a A . should_be_true
r3.is_a B . should_be_true
r3.a_method . should_equal "A method"
r3.b_method . should_equal "B method"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: 📤 Backlog
Development

No branches or pull requests

2 participants