Repository navigation
A type predicate whose constraint fails no longer warns; a real violation warns once - #594
Merged
ASDAlexander77 merged 1 commit intoOct 17, 2026
Conversation
…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
deleted the
claude/fix-type-predicate-constraint-warning-468703
branch
October 17, 2026 17:38
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
testConstraintemitted "Type X does not satisfy the constraint Y." itself, before the caller could decide whether the failure was an error. Two cases were wrong:__is<V extends T, T>and__is_any<V extends never>fail their constraint on purpose, and the call folds tofalse(MLIRGenGenerics.cpp). They still warned from insidelib.generics.ts, so everyreducewhose accumulator type differs from the element type warned, and so did everyMapwith a non-string key (HashHelper.hashCode).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 ...andType s32 ....Fix
testConstrainttakes a newbool reportFailure = trueparameter:!isTypePredicate.false.Verification
lines.reduce((m, line) => Math.max(m, w(line)), 0.0)andnew Map<int, string>()withm.set/m.getcompile under--emit=jit(without--nowarn) with no warnings, and still print6anda.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.test/tester/constraint-warning/:test-compile-constraint-warning-type-predicate: self-containedisOf/isAnypredicates, inferred and explicit. It fails on any warning.test-compile-constraint-warning-violation: the singles32warning must appear, andType 1 ...must not.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
reducecalls 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