GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: wrap small integers before casting them to bool by SwastikTripathi · Pull Request #3065 · AssemblyScript/assemblyscript

Conversation

@SwastikTripathi

@SwastikTripathi SwastikTripathi commented Nov 12, 2026

Copy link
Copy Markdown

Fixes #3057.

Changes proposed in this pull request:
An explicit cast of a small integer (i8, u8, i16, u16) to bool (<bool>x, x as bool, bool(x)) now clears the bits above the small type before testing the value. Before, convertExpression only wrapped small integers when converting to a larger type, and bool (size 1) never qualified, so a value that overflowed to 0 in its own type still tested as true:

function f(a: u8): bool {
  let c: u8 = a + 1;
  return <bool>c;
}
f(255); // true before, false now (c is 0)

The conditional form (c ? true : false) already went through makeIsTrueish, which wraps, so only the explicit cast was affected.

Added cases to tests/compiler/bool.ts for u8, i8, u16 and i16 values that wrap to 0 (and some that don't). With the old compiler the module aborts on the first new assertion; with the fix it runs. Regenerated the bool and cast fixtures; cast.debug.wat changes because it contains such casts (an i32.and/sign-extension now precedes the i32.ne). npm run test:compiler passes.

  • I've read the contributing guidelines
  • I've added my name and email to the NOTICE file

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@SwastikTripathi
fix: wrap small integers before casting them to bool
b8fbb0c

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Explicit bool cast of u8/i8/u16/i16 does not truncate high bits

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@SwastikTripathi
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.