diff options
| author | Bradley Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-08-11 16:16:48 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-11 16:16:48 -0400 |
| commit | 55acd3fe129551dd0ce231390f8d07a446754efe (patch) | |
| tree | 3529baa929ad360af1922f786843160f1287065d | |
| parent | fa321af72d7b8c5614a5d9745b56e9df119f5842 (diff) | |
| parent | 3bc8007c8135a9f47842bb100f1527793ef678f3 (diff) | |
Merge pull request #853 from BradLewis/fix/resolve-bit-set-union-intersection
Correctly resolve bit_set union and intersections with comp lits
| -rw-r--r-- | src/server/analysis.odin | 15 | ||||
| -rw-r--r-- | tests/hover_test.odin | 36 |
2 files changed, 50 insertions, 1 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index b63c89b..e001294 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -2760,6 +2760,13 @@ resolve_binary_expression :: proc(ast_context: ^AstContext, binary: ^ast.Binary_ } if !ok_a || !ok_b { + // we return the type that was correctly resolved, if one of them was + if ok_a { + return symbol_a, true + } + if ok_b { + return symbol_b, true + } return {}, false } @@ -2778,6 +2785,13 @@ resolve_binary_expression :: proc(ast_context: ^AstContext, binary: ^ast.Binary_ } if !ok_a || !ok_b { + // we return the type that was correctly resolved, if one of them was + if ok_a { + return symbol_a, true + } + if ok_b { + return symbol_b, true + } return {}, false } @@ -2819,7 +2833,6 @@ resolve_binary_expression :: proc(ast_context: ^AstContext, binary: ^ast.Binary_ return symbol_b, true } - //Otherwise just choose the first type, we do not handle error cases - that is done with the checker return symbol_a, ok_a } diff --git a/tests/hover_test.odin b/tests/hover_test.odin index 684d457..916a247 100644 --- a/tests/hover_test.odin +++ b/tests/hover_test.odin @@ -3662,6 +3662,42 @@ ast_hover_union_with_align :: proc(t: ^testing.T) { "test.Foo: union #no_nil #align(4) {\n\tint,\n\tstring,\n}" ) } + +@(test) +ast_hover_bit_set_intersection :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + Flag :: enum u8 {Foo, Bar} + Flags :: distinct bit_set[Flag; u8] + + foo_bar := Flags{.Foo, .Bar} // foo_bar: bit_set[Flag] + foo_{*}b := foo_bar & {.Foo} // hover for foo_b + `, + } + test.expect_hover( + t, + &source, + "test.foo_b: bit_set[Flag]\n// hover for foo_b" + ) +} + +@(test) +ast_hover_bit_set_union :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + Flag :: enum u8 {Foo, Bar} + Flags :: distinct bit_set[Flag; u8] + + foo_bar := Flags{.Bar} // foo_bar: bit_set[Flag] + foo_{*}b := {.Foo} | foo_bar // hover for foo_b + `, + } + test.expect_hover( + t, + &source, + "test.foo_b: bit_set[Flag]\n// hover for foo_b" + ) +} /* Waiting for odin fix |