diff --git a/examples/tests/invalid/inference.w b/examples/tests/invalid/inference.w index 39a3a6d32d3..11b173a0493 100644 --- a/examples/tests/invalid/inference.w +++ b/examples/tests/invalid/inference.w @@ -80,4 +80,7 @@ class NeedAnnotations { // ^^^^ Missing required type annotation for method signature log(nice); } -} \ No newline at end of file +} + +let badFunc: inflight (str): void = inflight (arg1: num) => {}; +// ^^^^^^^^^^^^^^^^^^^^^^^^^^ Expected type to be "inflight (str): void", but got "inflight (arg1: num): unknown" instead diff --git a/libs/wingc/src/type_check.rs b/libs/wingc/src/type_check.rs index 5b9e3809180..7b96e49b602 100644 --- a/libs/wingc/src/type_check.rs +++ b/libs/wingc/src/type_check.rs @@ -2419,7 +2419,8 @@ impl<'a> TypeChecker<'a> { if expected_types.len() == 1 { // First check if the actual type is an inference that can be replaced with the expected type if self.add_new_inference(&actual_type, &expected_types[0]) { - return_type = expected_types[0]; + // Update the type we validate and return + return_type = self.types.maybe_unwrap_inference(return_type); } else { // otherwise, check if the expected type is an inference that can be replaced with the actual type self.add_new_inference(&expected_types[0], &actual_type); diff --git a/tools/hangar/__snapshots__/invalid.ts.snap b/tools/hangar/__snapshots__/invalid.ts.snap index 16d181e64db..91904806b2d 100644 --- a/tools/hangar/__snapshots__/invalid.ts.snap +++ b/tools/hangar/__snapshots__/invalid.ts.snap @@ -437,6 +437,17 @@ exports[`cloud_function_expects_inflight.w 1`] = ` | \\\\-^ Expected type to be \\"inflight (event: str): void\\", but got \\"preflight (name: str): str\\" instead +error: Expected type to be \\"inflight (message: str): void\\", but got \\"inflight (x: num): unknown\\" instead + --> ../../../examples/tests/invalid/cloud_function_expects_inflight.w:9:15 + | + 9 | q.setConsumer(inflight (x: num) => { + | /---------------^ +10 | | // ^ \\"num\\" doesn't match the expected type \\"str\\" +11 | | return; +12 | | }); + | \\\\-^ Expected type to be \\"inflight (message: str): void\\", but got \\"inflight (x: num): unknown\\" instead + + Tests 1 failed (1) @@ -882,6 +893,13 @@ error: Expected \\"Json\\" elements to be Json values (https://www.json.org/json | ^^^^^^^^^^^^^^^^^ Expected \\"Json\\" elements to be Json values (https://www.json.org/json-en.html), but got \\"Array\\" which is not a Json value +error: Expected type to be \\"inflight (str): void\\", but got \\"inflight (arg1: num): unknown\\" instead + --> ../../../examples/tests/invalid/inference.w:85:37 + | +85 | let badFunc: inflight (str): void = inflight (arg1: num) => {}; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ Expected type to be \\"inflight (str): void\\", but got \\"inflight (arg1: num): unknown\\" instead + + error: Unexpected return value from void function. Return type annotations are required for methods. --> ../../../examples/tests/invalid/inference.w:76:5 |