From 872abae80782a7d6f14420b0ad7a8686d49253d5 Mon Sep 17 00:00:00 2001 From: Sean Huh Date: Thu, 10 Sep 2026 18:27:12 +0000 Subject: [PATCH 1/2] Add checker conformance tests for type parameter deduction for type(t) --- .../simple/testdata/type_deduction.textproto | 166 ++++++++++++++++++ 1 file changed, 166 insertions(+) diff --git a/tests/simple/testdata/type_deduction.textproto b/tests/simple/testdata/type_deduction.textproto index 1a0e2611..b9a1ad64 100644 --- a/tests/simple/testdata/type_deduction.textproto +++ b/tests/simple/testdata/type_deduction.textproto @@ -951,3 +951,169 @@ section { } } } + +section { + name: "type_parameters_in_type_type" + description: "Tests for type parameter deduction within TypeType (type(T))." + test { + name: "type_param_in_type_type_int" + check_only: true + expr: "cast('hello', int)" + type_env { + name: "cast" + function { + overloads { + overload_id: "cast_val_to_type" + params { dyn {} } + params { + type { + type_param: "T" + } + } + result_type { + type_param: "T" + } + } + } + } + typed_result { + deduced_type { + primitive: INT64 + } + } + } + test { + name: "type_param_in_type_type_string" + check_only: true + expr: "cast(123, string)" + type_env { + name: "cast" + function { + overloads { + overload_id: "cast_val_to_type" + params { dyn {} } + params { + type { + type_param: "T" + } + } + result_type { + type_param: "T" + } + } + } + } + typed_result { + deduced_type { + primitive: STRING + } + } + } + test { + name: "composite_type_param_in_type_type" + check_only: true + expr: "first_elem_type('data', type([1]))" + type_env { + name: "first_elem_type" + function { + overloads { + overload_id: "first_elem_type_list" + params { dyn {} } + params { + type { + list_type { + elem_type { + type_param: "T" + } + } + } + } + result_type { + type_param: "T" + } + } + } + } + typed_result { + deduced_type { + primitive: INT64 + } + } + } + test { + name: "nested_type_param_in_type_type" + check_only: true + expr: "unwrap_type(type(int))" + type_env { + name: "unwrap_type" + function { + overloads { + overload_id: "unwrap_type_t" + params { + type { + type { + type_param: "T" + } + } + } + result_type { + type { + type_param: "T" + } + } + } + } + } + typed_result { + deduced_type { + type { + primitive: INT64 + } + } + } + } + test { + name: "type_map_erasure_comparison" + check_only: true + expr: "type({}) == map" + typed_result { + deduced_type { + primitive: BOOL + } + } + } + test { + name: "type_list_erasure_comparison" + check_only: true + expr: "type([1]) == list" + typed_result { + deduced_type { + primitive: BOOL + } + } + } + test { + name: "type_comparison_different_types_inequality" + expr: "type(1) != type(1u)" + typed_result { + result { + bool_value: true + } + deduced_type { + primitive: BOOL + } + } + } + test { + name: "type_comparison_different_types_equality" + expr: "type(1) == type(1u)" + typed_result { + result { + bool_value: false + } + deduced_type { + primitive: BOOL + } + } + } +} From 98a1938c72c025c57747cbffc1ac6246737ef34d Mon Sep 17 00:00:00 2001 From: Sean Huh Date: Fri, 11 Sep 2026 19:33:12 +0000 Subject: [PATCH 2/2] Add test cases involving comprehensions' empty ranges --- .../simple/testdata/type_deduction.textproto | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/simple/testdata/type_deduction.textproto b/tests/simple/testdata/type_deduction.textproto index b9a1ad64..6546b044 100644 --- a/tests/simple/testdata/type_deduction.textproto +++ b/tests/simple/testdata/type_deduction.textproto @@ -1117,3 +1117,41 @@ section { } } } + +section { + name: "empty_range_nested_comprehensions" + description: "An empty iteration range gives the iteration variable a free type " + "variable rather than dyn. Using it as the range of a nested " + "comprehension must resolve it to dyn." + test { + name: "empty_list_range_nested_list_comprehension" + check_only: true + expr: "[].map(x, x.map(y, y))" + typed_result { + deduced_type { + list_type { elem_type { list_type { elem_type { dyn {} } } } } + } + } + } + test { + name: "empty_map_range_nested_comprehension" + check_only: true + expr: "{}.map(k, k.map(y, y))" + typed_result { + deduced_type { + list_type { elem_type { list_type { elem_type { dyn {} } } } } + } + } + } + test { + name: "empty_range_nested_comprehension_before_constraint" + description: "Inner comprehension widens the outer element type to dyn, so the " + "subsequent int comparison is legal." + expr: "[].all(x, x.all(y, y == 1) && x == 1)" + typed_result { + result { bool_value: true } + deduced_type { primitive: BOOL } + } + } +} +