You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A typed list literal accepts elements of another type: let ys: List[i32] = ["a", "b"] and let zs: List[str] = [1, 2] pass check #2348
Spec: §4.3c (a bracket literal is typed by its demand), §4.2.6 (no implicit conversion between unrelated types).
Repro (installed compiler on main, 14a720bd7):
fn main:
let ys: List[i32] = ["a", "b"]
let zs: List[str] = [1, 2]
print(f"{ys[0]} {zs.len()}")
Expected: two type errors (a str where an i32 is demanded, an integer where a str is).
Actual: with check passes with no diagnostic; with run prints 1 for a program that reads a str's first word as an i32.
Found while writing the D116 ++ compile-error fixture (err_d116_mixed_elements.w): the element types must be one, and the first draft of the fixture was accepted because the annotated literal never rejected its elements. The ++ check now refuses the mix on its own; the typed-literal gap is separate.
fn take(xs: List[i32]) -> isize: xs.len()
let a: List[i32] = ["a"] // accepted
let b: List[i32] = [1, "a"] // refused: "sequence literal expressions do not establish one compatible owned result type"
let c = take(["z"]) // accepted
var d: List[i32] = List.new()
d.push("q") // refused: wrong argument type in call to 'List.push'
So the hole is a homogeneous literal whose elements all have one type that is not the demanded element: check_array_literal sets expected_elem from the annotation or parameter, and check_list_literal_elem compares types_compatible(elem_ty, actual_ty) then falls to emit_argument_type_mismatch("List.literal", …), yet no diagnostic lands; either types_compatible(i32, str) answers yes on this path or the mismatch emitter drops the "List.literal" callee. A trace at check_list_literal_elem with the two types decides it; one build.
Traced one step further on branch gaps-2: for let a: List[i32] = ["a"] and take(["z"]), check_list_literal_elem is never reached (a trace there printed nothing for the file), so the homogeneous literal is typed by a different route under an annotation or parameter demand (the D93/D113 literal-by-use path, collection_literal_hints / literal_decision), which never compares the literal's own element type with the demanded one. The fix belongs where that route adopts the demanded List type for the literal: compare its element with the elements' established type and refuse a mismatch there.
Fixed on branch gaps-3 (from a31a7df; gate running): in check_array_literal, after resolve_contextual_join, the joined element type must be compatible with the demanded element (or an arithmetic widening of it); otherwise sequence literal element is \str` where `i32` is demanded (§4.3c)`. The literal was typed as the demanded collection regardless. Fixture test/compile_errors/err_2348_typed_literal_foreign_element.w; the D93/D113/D116/D128 literal-typing tests and int-local-rechecks=0 unchanged.
Fixed: a sequence literal typed by a demand must hold the demanded element (check_array_literal, §4.3c); fixture err_2348_typed_literal_foreign_element.w.
Activity
ehartford commentedon Oct 12, 2026
Narrowed on main
c97a00852:So the hole is a homogeneous literal whose elements all have one type that is not the demanded element:
check_array_literalsetsexpected_elemfrom the annotation or parameter, andcheck_list_literal_elemcomparestypes_compatible(elem_ty, actual_ty)then falls toemit_argument_type_mismatch("List.literal", …), yet no diagnostic lands; eithertypes_compatible(i32, str)answers yes on this path or the mismatch emitter drops the "List.literal" callee. A trace atcheck_list_literal_elemwith the two types decides it; one build.ehartford commentedon Oct 12, 2026
Traced one step further on branch gaps-2: for
let a: List[i32] = ["a"]andtake(["z"]),check_list_literal_elemis never reached (a trace there printed nothing for the file), so the homogeneous literal is typed by a different route under an annotation or parameter demand (the D93/D113 literal-by-use path,collection_literal_hints/literal_decision), which never compares the literal's own element type with the demanded one. The fix belongs where that route adopts the demanded List type for the literal: compare its element with the elements' established type and refuse a mismatch there.ehartford commentedon Oct 12, 2026
Fixed on branch gaps-3 (from a31a7df; gate running): in
check_array_literal, afterresolve_contextual_join, the joined element type must be compatible with the demanded element (or an arithmetic widening of it); otherwisesequence literal element is \str` where `i32` is demanded (§4.3c)`. The literal was typed as the demanded collection regardless. Fixture test/compile_errors/err_2348_typed_literal_foreign_element.w; the D93/D113/D116/D128 literal-typing tests and int-local-rechecks=0 unchanged.#2348 (§4.3c): a sequence literal typed by a demand must hold the dem…
#2348 (§4.3c): a sequence literal typed by a demand must hold the dem…
ehartford commentedon Oct 12, 2026
Fixed: a sequence literal typed by a demand must hold the demanded element (
check_array_literal, §4.3c); fixture err_2348_typed_literal_foreign_element.w.