Skip to content

A type predicate whose constraint fails no longer warns; a real violation warns once - #594

Merged
ASDAlexander77 merged 1 commit into
mainfrom
claude/fix-type-predicate-constraint-warning-468703
Oct 17, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
claude/fix-type-predicate-constraint-warning-468703

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Problem

testConstraint emitted "Type X does not satisfy the constraint Y." itself, before the caller could decide whether the failure was an error. Two cases were wrong:

  • Type-predicate guards in the DefaultLib. __is<V extends T, T> and __is_any<V extends never> fail their constraint on purpose, and the call folds to false (MLIRGenGenerics.cpp). They still warned from inside lib.generics.ts, so every reduce whose accumulator type differs from the element type warned, and so did every Map with a non-string key (HashHelper.hashCode).
  • The inference-only call in zipTypeParameterWithArgument. Its result is ignored and the constraint is checked again later, but it warned anyway. Because of that, a real violation warned twice: Type 1 ... and Type s32 ....

Fix

testConstraint takes a new bool reportFailure = true parameter:

  • The final check in the instantiation passes !isTypePredicate.
  • The inference call passes false.

Verification

  • lines.reduce((m, line) => Math.max(m, w(line)), 0.0) and new Map<int, string>() with m.set/m.get compile under --emit=jit (without --nowarn) with no warnings, and still print 6 and a.
  • function f<T extends string>(t: T) { return t; } print(f(1)); now gives a single warning, Type s32 does not satisfy the constraint string.
  • New tests under test/tester/constraint-warning/:
    • test-compile-constraint-warning-type-predicate: self-contained isOf/isAny predicates, inferred and explicit. It fails on any warning.
    • test-compile-constraint-warning-violation: the single s32 warning must appear, and Type 1 ... must not.
    • Both fail against the previous compiler.
  • ctest -C Release -j 8 --timeout 300: 4126/4126 passed.

Follow-up (not in this PR)

native_ts_graphics can turn two text-width loops into reduce calls that no longer warn. This was tried and reverted on 2026-10-17 because of this warning.

  • examples/mouse_cursor.ts (centered): lines.reduce((w, line) => Math.max(w, Donut_ImGuiCalcTextWidth(line)), 0.0)
  • examples/raytracing_ao.ts (menu box): this.menuLines.reduce((w, menuLine) => Math.max(w, Donut_ImGuiCalcTextWidth(menuLine)), 0.0)

🤖 Generated with Claude Code

…tion warns once

`testConstraint` warned "Type X does not satisfy the constraint Y." itself, before its caller
could decide whether the failure was an error. The DefaultLib's compile-time type tests
(`__is<V extends T, T>`, `__is_any<V extends never>`, used by `reduce`/`reduceRight` and
`HashHelper.hashCode`) fail their constraint on purpose and fold to `false`, so any `reduce`
with an accumulator of another type, or any `Map` with a non-string key, warned from inside
the DefaultLib.

`testConstraint` takes `reportFailure` now: the final check in the instantiation passes
`!isTypePredicate`, and the inference-only call in `zipTypeParameterWithArgument`, whose
result is ignored and checked again later, passes `false`. That call was also why a real
violation (`f<T extends string>(1)`) warned twice ("Type 1 ..." and "Type s32 ...").

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 76125ea into main Oct 17, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the claude/fix-type-predicate-constraint-warning-468703 branch October 17, 2026 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant