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, cgen: fix comptime issues with generic type #22751

Merged
merged 8 commits into from
Nov 5, 2024

Conversation

felipensp
Copy link
Member

@felipensp felipensp commented Nov 3, 2024

Fix #22710
Fix #22642

This PR fixes issues like:

With default type codegen:

var := T{}

where T is a non-struct type (e.g. map[K]T or []T).

mut variables assignment from generic fn return

mut v := func[T]()
pritnln(v)

selector expr with .str on generic type

a := T{}
assert a.str != unsafe { nil } 

And possible regeneration of already generated closure.

rename g.comptime.get_comptime_var_type to g.comptime.get_type.

Huly®: V_0.6-21197

@felipensp felipensp marked this pull request as ready for review November 4, 2024 15:27
@@ -53,6 +53,7 @@ fn (mut g Gen) struct_init(node ast.StructInit) {
if mut sym.info is ast.Struct {
is_anon = sym.info.is_anon
}
is_generic_default := sym.kind !in [.struct, .array_fixed] && node.typ.has_flag(.generic) // T{}
Copy link
Member

Choose a reason for hiding this comment

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

I do not understand, how is not being a struct or fixed array related to a property named is_generic_default?

Copy link
Member

Choose a reason for hiding this comment

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

Can you add a small comment here, mentioning var := X{} , for X being map[K]T or []T ?

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 d9c3ac5 into vlang:master Nov 5, 2024
71 checks passed
spytheman pushed a commit that referenced this pull request Nov 6, 2024
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.

cgen erros: Generic initialization. setting memory to nil? generic checker error
2 participants