diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2024-10-05 13:33:22 +0200 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2024-10-05 13:33:22 +0200 |
| commit | 8da9a96b7e85c6366b8e7286bee4543a9b195d04 (patch) | |
| tree | 20d71e7f33e0678dc48088cfef3d47fecb4eb3d5 /src | |
| parent | e0dc37746a0cab0cc714212b756cce309f1c9914 (diff) | |
Fix issue with comp literals and `&` in type
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/ast.odin | 25 | ||||
| -rw-r--r-- | src/server/analysis.odin | 10 |
2 files changed, 28 insertions, 7 deletions
diff --git a/src/common/ast.odin b/src/common/ast.odin index af3c812..4a576d7 100644 --- a/src/common/ast.odin +++ b/src/common/ast.odin @@ -146,6 +146,31 @@ get_attribute_objc_is_class_method :: proc(attributes: []^ast.Attribute) -> bool return false } +unwrap_comp_literal :: proc(expr: ^ast.Expr) -> (^ast.Comp_Lit, int, bool) { + n := 0 + expr := expr + for expr != nil { + if unary, ok := expr.derived.(^ast.Unary_Expr); ok { + if unary.op.kind == .And { + expr = unary.expr + n += 1 + } + } else { + break + } + } + + if expr != nil { + if comp_literal, ok := expr.derived.(^ast.Comp_Lit); ok { + return comp_literal, n, ok + } + + return {}, n, false + } + + return {}, n, false +} + unwrap_pointer_ident :: proc(expr: ^ast.Expr) -> (ast.Ident, int, bool) { n := 0 expr := expr diff --git a/src/server/analysis.odin b/src/server/analysis.odin index 36d6781..e153cac 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -219,13 +219,14 @@ resolve_type_comp_literal :: proc( set_ast_package_set_scoped(ast_context, current_symbol.pkg) + for elem, element_index in current_comp_lit.elems { if !position_in_node(elem, position_context.position) { continue } if field_value, ok := elem.derived.(^ast.Field_Value); ok { //named - if comp_lit, ok := field_value.value.derived.(^ast.Comp_Lit); ok { + if comp_lit, ref_n, ok := common.unwrap_comp_literal(field_value.value); ok { if s, ok := current_symbol.value.(SymbolStructValue); ok { for name, i in s.names { if name == field_value.field.derived.(^ast.Ident).name { @@ -250,12 +251,7 @@ resolve_type_comp_literal :: proc( } } - return resolve_type_comp_literal( - ast_context, - position_context, - symbol, - cast(^ast.Comp_Lit)field_value.value, - ) + return resolve_type_comp_literal(ast_context, position_context, symbol, comp_lit) } } } |