Skip to content

checker: check struct aliased field unsign type assigning negative value (fix #22868) - #22871

Merged
spytheman merged 1 commit into
vlang:masterfrom
yuyi98:check_struct_field_init
Nov 16, 2024
Merged

spytheman merged 1 commit into
vlang:masterfrom
yuyi98:check_struct_field_init

Conversation

@yuyi98

@yuyi98 yuyi98 commented Nov 16, 2024 •

Copy link
Copy Markdown
Member

This PR check struct aliased field unsign type assigning negative value (fix #22868).

  • Check struct aliased field unsign type assigning negative value.
  • Add test.
type Port = u16

struct App {
	port Port
}

fn main() {
	app := App{
		port: -1
	}
	println(app)
}

PS D:\Test\v\tt1> v run .
tt1.v:9:9: error: cannot assign negative value to unsigned integer type
    7 | fn main() {
    8 |     app := App{
    9 |         port: -1
      |               ~~
   10 |     }
   11 |     println(app)

Huly®: V_0.6-21314

@spytheman spytheman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Excellent work.

@spytheman
spytheman merged commit 8300a06 into vlang:master Nov 16, 2024
@yuyi98
yuyi98 deleted the check_struct_field_init branch November 16, 2024 11:28
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.

Type alias looses unsigned integer negative value check at compile time

2 participants