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: fix checking give const map as default or init value to struct fields(fix #20512) #20546

Merged
merged 2 commits into from
Jan 15, 2024

Conversation

shove70
Copy link
Contributor

@shove70 shove70 commented Jan 15, 2024

  1. Fixed Mutable map field, initialised with const, makes const mutable #20512
  2. Add tests.
const const_map = {
	'key': 4
}

struct Foo {
mut:
	field map[string]int = const_map
}

fn main() {
	_ = Foo{
		field: const_map
	}
}

outputs:

a.v:7:25: error: cannot copy map: call `move` or `clone` method (or use a reference)
    5 | struct Foo {
    6 | mut:
    7 |     field map[string]int = const_map
      |                            ~~~~~~~~~
    8 | }
    9 |
a.v:12:10: error: cannot assign a const map to mut struct field, call `clone` method (or use a reference)
   10 | fn main() {
   11 |     _ = Foo{
   12 |         field: const_map
      |                ~~~~~~~~~
   13 |     }
   14 | }

@shove70 shove70 changed the title checker: fix checking give static map as default or init value to struct fields(fix #20512) checker: fix checking give const map as default or init value to struct fields(fix #20512) Jan 15, 2024
@spytheman spytheman merged commit df8f8ae into vlang:master Jan 15, 2024
54 checks passed
@shove70 shove70 deleted the patch-1 branch January 15, 2024 21:55
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.

Mutable map field, initialised with const, makes const mutable
2 participants