Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 166 additions & 0 deletions tests/simple/testdata/type_deduction.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add explicit tests for the edge cases around free parameters?

I don't think these are super practical expressions but maybe better to document the weirdness than not?

It's also a bit of a can of worms so it might be fine to leave unspecified for now until we sort out the other issues with type unification.

I think the updates in C++ and java have us with something like:

[type([]), int]  -> list(dyn)

[] + [[type(1)]] + [[type([])]]  -> list<list<dyn>>

false ? int : type([]) -> no overload

@l46kok l46kok Sep 10, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me send these out as a separate PR, the [] + [[type(1)]] + [[type([])]] case especially requires further discussion (all of the stacks are divergent, so we need to decide on a behavior)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I seem to recall empty iteration ranges within nested comprehensions have an odd effect on type unification as well

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
}
}
}
}
Loading