Skip to content

Fix typed select to propagate result type instead of Any#2698

Closed
sumleo wants to merge 1 commit intoWebAssembly:mainfrom
sumleo:fix/typed-select-result-type
Closed

Fix typed select to propagate result type instead of Any#2698
sumleo wants to merge 1 commit intoWebAssembly:mainfrom
sumleo:fix/typed-select-result-type

Conversation

@sumleo
Copy link
Copy Markdown
Contributor

@sumleo sumleo commented Feb 25, 2026

Summary

When processing a typed select instruction (one with an explicit type annotation), TypeChecker::OnSelect() validates both operand types against the expected type but never assigns the validated type to result_type. It stays as Type::Any from initialization, causing PushType(Type::Any) instead of pushing the declared result type.

This violates the WebAssembly spec, which requires a typed select to produce a value of the annotated type on the value stack. The untyped select path already correctly sets result_type = type1; this fix applies the analogous assignment for the typed path: result_type = expected[0].

The Fix

A single line addition after the type checks in the typed select branch:

result_type = expected[0];

This ensures the annotated type flows through to PushType(result_type) and PrintStackIfFailed().

Test plan

  • Verified the changed file compiles cleanly
  • The fix is a minimal, obvious correction consistent with the existing untyped select logic

In OnSelect(), when a typed select instruction has an explicit type
annotation (non-empty expected vector), the code validates both operand
types against expected[0] but never assigns the result_type. It remains
Type::Any from initialization, so PushType(Type::Any) is called instead
of pushing the declared result type.

This violates the WebAssembly spec which requires a typed select to
produce a value of the annotated type. The untyped select path already
correctly sets result_type = type1; this commit applies the analogous
fix for the typed path by setting result_type = expected[0].
@sumleo
Copy link
Copy Markdown
Contributor Author

sumleo commented Feb 26, 2026

Closing as duplicate of #2707.

@sumleo sumleo closed this Feb 26, 2026
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