aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-11-16 15:30:54 -0500
committerBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-11-16 15:30:54 -0500
commit12deb18a07dc28f840555fb6c875d888ab5be13b (patch)
treee26678f19ec0ee3e33ea0abdf928d95ada721118
parentb893410bc7ff44a73f4c77d31d7ae5c7defbd9e6 (diff)
Correct resolving unary exprs immediately after a function call
-rw-r--r--src/server/analysis.odin17
-rw-r--r--tests/hover_test.odin33
2 files changed, 46 insertions, 4 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin
index 45bf0fd..c9a6275 100644
--- a/src/server/analysis.odin
+++ b/src/server/analysis.odin
@@ -1223,13 +1223,22 @@ internal_resolve_type_expression :: proc(ast_context: ^AstContext, node: ^ast.Ex
case ^Comp_Lit:
return internal_resolve_type_expression(ast_context, v.type, out)
case ^Unary_Expr:
+ ok := internal_resolve_type_expression(ast_context, v.expr, out)
if v.op.kind == .And {
- ok := internal_resolve_type_expression(ast_context, v.expr, out)
out.pointers += 1
- return ok
- } else {
- return internal_resolve_type_expression(ast_context, v.expr, out)
+ } else if v.op.kind == .Sub || v.op.kind == .Add {
+ if value, ok := out.value.(SymbolProcedureValue); ok {
+ if len(value.return_types) > 0 {
+ type := value.return_types[0].type
+ if type == nil {
+ type = value.return_types[0].default_value
+ }
+ ok = internal_resolve_type_expression(ast_context, type, out)
+ return ok
+ }
+ }
}
+ return ok
case ^Deref_Expr:
ok := internal_resolve_type_expression(ast_context, v.expr, out)
out.pointers -= 1
diff --git a/tests/hover_test.odin b/tests/hover_test.odin
index 52dca76..8d5f461 100644
--- a/tests/hover_test.odin
+++ b/tests/hover_test.odin
@@ -5642,6 +5642,39 @@ ast_hover_named_proc_arg_hover :: proc(t: ^testing.T) {
}
test.expect_hover(t, &source, "foo.bar: f32")
}
+
+@(test)
+ast_hover_unary_function_call :: proc(t: ^testing.T) {
+ source := test.Source {
+ main = `package test
+ foo :: proc() -> int {}
+
+ main :: proc() {
+ b{*}ar := -foo()
+ }
+ `,
+ }
+ test.expect_hover(t, &source, "test.bar: int")
+}
+
+@(test)
+ast_hover_unary_overload_function_call :: proc(t: ^testing.T) {
+ source := test.Source {
+ main = `package test
+ foo_int :: proc() -> int {}
+ foo_string :: proc(s: string) -> string {}
+ foo :: proc {
+ foo_int,
+ foo_string,
+ }
+
+ main :: proc() {
+ b{*}ar := -foo()
+ }
+ `,
+ }
+ test.expect_hover(t, &source, "test.bar: int")
+}
/*
Waiting for odin fix