Skip to content

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

@radeusgd

Description

@radeusgd

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"

Metadata

Metadata

Type

Projects

Status

🟢 Accepted

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions