From dbb1c49d04abadc3014ea14220b9e73aaa255435 Mon Sep 17 00:00:00 2001 From: Alex Trotta Date: Sun, 4 Oct 2026 04:42:29 +0200 Subject: [PATCH 1/2] fix: Allow union types in function returns We were expecting a single non-union type as the return type, now this covers both cases. --- crates/starpls_parser/src/grammar/type_comments.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/starpls_parser/src/grammar/type_comments.rs b/crates/starpls_parser/src/grammar/type_comments.rs index 47336cb4..3cb72c5b 100644 --- a/crates/starpls_parser/src/grammar/type_comments.rs +++ b/crates/starpls_parser/src/grammar/type_comments.rs @@ -136,7 +136,7 @@ pub(crate) fn function_type(p: &mut Parser) -> CompletedMarker { p.error_recover_until("Expected \"->\"", EMPTY); return m.complete(p, FUNCTION_TYPE); } - type_(p); + union_type(p); m.complete(p, FUNCTION_TYPE) } From 67e4a57bdee3d044f43ea7ff3e59bfa606ee9a07 Mon Sep 17 00:00:00 2001 From: Alex Trotta Date: Sun, 4 Oct 2026 06:05:29 +0200 Subject: [PATCH 2/2] test --- crates/starpls_hir/src/typeck/tests.rs | 55 +++++++++++++++----------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/crates/starpls_hir/src/typeck/tests.rs b/crates/starpls_hir/src/typeck/tests.rs index 98d04ad7..6b4e65c2 100644 --- a/crates/starpls_hir/src/typeck/tests.rs +++ b/crates/starpls_hir/src/typeck/tests.rs @@ -389,6 +389,10 @@ def bar(x): # type: (int | string | None) -> None pass +def baz(): + # type: () -> string | int | None + pass + x = 1 # type: int | None foo(x) bar(x) @@ -399,31 +403,36 @@ bar(y) y = "goodbye" # type: int | string | float | None bar(y) + +z = baz() "#, expect![[r#" - 113..114 "x": int | None - 117..118 "1": Literal[1] - 138..141 "foo": def foo(x: int) -> None - 142..143 "x": int | None - 138..144 "foo(x)": None - 145..148 "bar": def bar(x: int | string | None) -> None - 149..150 "x": int | None - 145..151 "bar(x)": None - 152..155 "bar": def bar(x: int | string | None) -> None - 156..157 "2": Literal[2] - 152..158 "bar(2)": None - 160..161 "y": int | string - 164..171 "\"hello\"": Literal["hello"] - 193..196 "bar": def bar(x: int | string | None) -> None - 197..198 "y": int | string - 193..199 "bar(y)": None - 201..202 "y": int | string | float | None - 205..214 "\"goodbye\"": Literal["goodbye"] - 251..254 "bar": def bar(x: int | string | None) -> None - 255..256 "y": int | string | float | None - 251..257 "bar(y)": None - - 255..256 Argument of type "int | string | float | None" cannot be assigned to parameter of type "int | string | None" + 172..173 "x": int | None + 176..177 "1": Literal[1] + 197..200 "foo": def foo(x: int) -> None + 201..202 "x": int | None + 197..203 "foo(x)": None + 204..207 "bar": def bar(x: int | string | None) -> None + 208..209 "x": int | None + 204..210 "bar(x)": None + 211..214 "bar": def bar(x: int | string | None) -> None + 215..216 "2": Literal[2] + 211..217 "bar(2)": None + 219..220 "y": int | string + 223..230 "\"hello\"": Literal["hello"] + 252..255 "bar": def bar(x: int | string | None) -> None + 256..257 "y": int | string + 252..258 "bar(y)": None + 260..261 "y": int | string | float | None + 264..273 "\"goodbye\"": Literal["goodbye"] + 310..313 "bar": def bar(x: int | string | None) -> None + 314..315 "y": int | string | float | None + 310..316 "bar(y)": None + 318..319 "z": string | int | None + 322..325 "baz": def baz() -> string | int | None + 322..327 "baz()": string | int | None + + 314..315 Argument of type "int | string | float | None" cannot be assigned to parameter of type "int | string | None" "#]], ) }