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

checker: disallow sum type holding alias ptrs #20786

Merged
merged 4 commits into from
Feb 13, 2024

Conversation

Delta456
Copy link
Member

Fixes #20782

@MCausc78
Copy link
Contributor

vlib/v/checker/tests/sum_type_holding_alias_ptr_err.vv:3:12: error: sum type cannot hold a reference type 
     1 | type Alias1 = &int 
     2 | type Alias2 = &string 
     3 | type Qwe = Alias1 | Alias2 
       |            ~~~~~~ 
     4 |  
     5 | fn main() { 
 Details: declare the sum type with non-reference types: `Qwe = Alias1 | ...` 
 and use a reference to the sum type instead: `var := &Qwe(Alias1(val))`

Can we get other Details message?

@Delta456
Copy link
Member Author

vlib/v/checker/tests/sum_type_holding_alias_ptr_err.vv:3:12: error: sum type cannot hold a reference type 
     1 | type Alias1 = &int 
     2 | type Alias2 = &string 
     3 | type Qwe = Alias1 | Alias2 
       |            ~~~~~~ 
     4 |  
     5 | fn main() { 
 Details: declare the sum type with non-reference types: `Qwe = Alias1 | ...` 
 and use a reference to the sum type instead: `var := &Qwe(Alias1(val))`

Can we get other Details message?

Like what?

@MCausc78
Copy link
Contributor

vlib/v/checker/tests/sum_type_holding_alias_ptr_err.vv:3:12: error: sum type cannot hold a reference type 
     1 | type Alias1 = &int 
     2 | type Alias2 = &string 
     3 | type Qwe = Alias1 | Alias2 
       |            ~~~~~~ 
     4 |  
     5 | fn main() { 
 Details: declare the sum type with non-reference types: `Qwe = Alias1 | ...` 
 and use a reference to the sum type instead: `var := &Qwe(Alias1(val))`

Can we get other Details message?

Like what?

Current one is confusing, since Qwe = Alias1 | ... declares sumtype with reference, something like declare alias as non-reference type, then declare sumtype as Qwe = Alias1

@Delta456
Copy link
Member Author

vlib/v/checker/tests/sum_type_holding_alias_ptr_err.vv:3:12: error: sum type cannot hold a reference type 
     1 | type Alias1 = &int 
     2 | type Alias2 = &string 
     3 | type Qwe = Alias1 | Alias2 
       |            ~~~~~~ 
     4 |  
     5 | fn main() { 
 Details: declare the sum type with non-reference types: `Qwe = Alias1 | ...` 
 and use a reference to the sum type instead: `var := &Qwe(Alias1(val))`

Can we get other Details message?

Like what?

Current one is confusing, since Qwe = Alias1 | ... declares sumtype with reference, something like declare alias as non-reference type, then declare sumtype as Qwe = Alias1

It makes it clear, thanks!

@MCausc78
Copy link
Contributor

Forbid type Foo = ∫ type Bar = Foo; type Baz = Bar | int | string too

@Delta456
Copy link
Member Author

type Foo = ∫ type Bar = Foo; type Baz = Bar | int | string

This already works

file.v:1:29: error: type `Foo` is an alias, use the original alias type `int` instead
    1 | type Foo = ∫ type Bar = Foo; type Baz = Bar | int | string
      |                             ~~~

@JalonSolov
Copy link
Contributor

Hmm... that last error message is incorrect/confusing. Should be fixed in another PR.

Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

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

Good work.

@spytheman spytheman merged commit 9f532f1 into vlang:master Feb 13, 2024
54 checks passed
@Delta456 Delta456 deleted the disallow_sum_type_alias_ptr branch February 13, 2024 17:19
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.

checker: no error on T | U, where T or U are reference types
4 participants