Title: Explicit bool cast of u8/i8/u16/i16 does not truncate high bits · Issue #3057 · AssemblyScript/assemblyscript · GitHub
Open Graph Title: Explicit bool cast of u8/i8/u16/i16 does not truncate high bits · Issue #3057 · AssemblyScript/assemblyscript
X Title: Explicit bool cast of u8/i8/u16/i16 does not truncate high bits · Issue #3057 · AssemblyScript/assemblyscript
Description: Bug description Explicitly casting a small integer (i8, u8, i16, u16) to bool via
Open Graph Description: Bug description Explicitly casting a small integer (i8, u8, i16, u16) to bool via
X Description: Bug description Explicitly casting a small integer (i8, u8, i16, u16) to bool via <bool>x, x as bool, or bool(x) emits i32.ne 0 without masking or sign-extending the operand first, so an over...
Opengraph URL: https://github.com/AssemblyScript/assemblyscript/issues/3057
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Explicit bool cast of u8/i8/u16/i16 does not truncate high bits","articleBody":"### Bug description\n\nExplicitly casting a small integer (`i8`, `u8`, `i16`, `u16`) to `bool` via `\u003cbool>x`, `x as bool`, or `bool(x)` emits `i32.ne 0` without masking or sign-extending the operand first, so an overflowed value that wraps to `0` evaluates to `true`.\n\nFor `a = 255` in the example below, `c` wraps to `0` in `u8`. Calling `g(255)` returns `0` (`false`), whereas `f(255)` returns `1` (`true`) because `f` compiles to `i32.add` followed directly by `i32.ne 0` without `i32.and 255`. Both functions should return `0` (`false`).\n\nThis happens because `convertExpression` only wraps short integers when `fromType.size \u003c toType.size`, skipping `bool` where `toType.size == 1`.\n\n### Steps to reproduce\n\n```ts\nexport function f(a: u8): bool {\n let c: u8 = a + 1;\n return \u003cbool>c;\n}\nexport function g(a: u8): bool {\n let c: u8 = a + 1;\n return c ? true : false;\n}\n```\n\nCredit: https://ucsbplse.github.io/\n\n### AssemblyScript version\n\nv0.28.20\n","author":{"url":"https://github.com/trackoor","@type":"Person","name":"trackoor"},"datePublished":"2026-11-07T02:26:45Z","url":"https://github.com/AssemblyScript/assemblyscript/issues/3057"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:cc9c7026-8936-52c7-1ed3-f5ea51051633 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8896:3E4AC7:2B60EC8:3B07104:6B0051EA |
| html-safe-nonce | 1ba878575491e7d21107e918669bd0a56ceb010e70594fb433d6c31c03ead099 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4ODk2OjNFNEFDNzoyQjYwRUM4OjNCMDcxMDQ6NkIwMDUxRUEiLCJ2aXNpdG9yX2lkIjoiMTM4NzEwMzUwMjk5OTc2OTU3OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 37772f858eeddf5fcfb90a6d92e58e346362a72b936116a28521a52333d43ea8 |
| hovercard-subject-tag | issue:6254172186 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/AssemblyScript/assemblyscript/3057/issue_layout |
| twitter:image | https://opengraph.githubassets.com/42156c5e2979b31cfeb540d665bb85b7dcef623674cef5505d7a81b2f7196620/AssemblyScript/assemblyscript/issues/3057 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/42156c5e2979b31cfeb540d665bb85b7dcef623674cef5505d7a81b2f7196620/AssemblyScript/assemblyscript/issues/3057 |
| og:image:alt | Bug description Explicitly casting a small integer (i8, u8, i16, u16) to bool via |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | trackoor |
| hostname | github.com |
| expected-hostname | github.com |
| None | f420f4996e6b1ff1ccd6d7683f8134f4b5f0f8a50124c210dbfe7490e5644abb |
| turbo-cache-control | no-preview |
| go-import | github.com/AssemblyScript/assemblyscript git https://github.com/AssemblyScript/assemblyscript.git |
| octolytics-dimension-user_id | 28916798 |
| octolytics-dimension-user_login | AssemblyScript |
| octolytics-dimension-repository_id | 105138356 |
| octolytics-dimension-repository_nwo | AssemblyScript/assemblyscript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 105138356 |
| octolytics-dimension-repository_network_root_nwo | AssemblyScript/assemblyscript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 26e00df917aba0f128135dc073ea0c5e33a70d40 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width