Title: Derived field initializers run before super(); Array#fill negative start corrupts memory; copyWithin traps when end < start · Issue #3064 · AssemblyScript/assemblyscript · GitHub
Open Graph Title: Derived field initializers run before super(); Array#fill negative start corrupts memory; copyWithin traps when end < start · Issue #3064 · AssemblyScript/assemblyscript
X Title: Derived field initializers run before super(); Array#fill negative start corrupts memory; copyWithin traps when end < start · Issue #3064 · AssemblyScript/assemblyscript
Description: Bug description Three differences from TypeScript/JavaScript semantics inside the documented subset (same results with -O0 and -O3): Field initializers of a derived class with an explicit constructor run before super() In a subclass with...
Open Graph Description: Bug description Three differences from TypeScript/JavaScript semantics inside the documented subset (same results with -O0 and -O3): Field initializers of a derived class with an explicit construct...
X Description: Bug description Three differences from TypeScript/JavaScript semantics inside the documented subset (same results with -O0 and -O3): Field initializers of a derived class with an explicit construct...
Opengraph URL: https://github.com/AssemblyScript/assemblyscript/issues/3064
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Derived field initializers run before super(); Array#fill negative start corrupts memory; copyWithin traps when end \u003c start","articleBody":"### Bug description\n\nThree differences from TypeScript/JavaScript semantics inside the documented subset (same results with `-O0` and `-O3`):\n\n1. **Field initializers of a derived class with an explicit constructor run before `super()`**\n\n In a subclass with an explicit constructor, field initializers are prepended to the constructor body (`compiler.ts`, `makeFieldInitializationInConstructor` before `bodyStartIndex`), so they run before the `super(...)` call and before the base class's own field initializers. Without an explicit subclass constructor the order is right.\n\n2. **`Array#fill(value, start)` with `start \u003c -length` writes before the buffer**\n\n In `FILL` (`std/assembly/util/bytes.ts`), `len` has type `usize` (unsigned), so `max(len + start, 0)` does not clamp a negative sum to `0` when `start \u003c -\u003cisize>len` and the loop writes before `dataStart`, corrupting the heap.\n\n3. **`copyWithin(target, start, end)` with `end \u003c start` traps**\n\n In `Array#copyWithin` (`std/assembly/array.ts`) and `TypedArray#copyWithin` (`std/assembly/typedarray.ts`), `count = min(last - from, len - to)` goes negative when `last \u003c from` and is cast to `usize` for `memory.copy`, trapping with `memory access out of bounds` instead of being a no-op.\n\n### Steps to reproduce\n\n```ts\n// 1. Derived field initializer runs before super()\nclass A { a: i32 = 1; constructor(a: i32) { this.a = a; } }\nclass B extends A { b: i32 = this.a * 10; constructor() { super(5); } }\nexport function f(): i32 { return new B().b; } // returns 0, expected 50\n\n// 2. Array#fill with start \u003c -length corrupts heap memory before the buffer\nexport function g(): i32 {\n const a: i32[] = [1, 2, 3, 4];\n a.fill(7, -9); // expected [7, 7, 7, 7]\n __collect();\n return a[0]; // aborts: \"null in ~lib/rt/itcms.ts:229:20\"\n}\n\n// 3. copyWithin with end \u003c start traps\nexport function h(): i32 {\n const a: i32[] = [1, 2, 3];\n a.copyWithin(1, 2, 1); // traps: \"memory access out of bounds\" (expected no-op)\n return a.length;\n}\n```\n\nCompile with `asc repro.ts -O0` (or `-O3`) and invoke `f()`, `g()`, and `h()`.\n\nPlayground: https://www.assemblyscript.org/editor.html#IyFydW50aW1lPWluY3JlbWVudGFsCmNsYXNzIEEgeyBhOiBpMzIgPSAxOyBjb25zdHJ1Y3RvcihhOiBpMzIpIHsgdGhpcy5hID0gYTsgfSB9CmNsYXNzIEIgZXh0ZW5kcyBBIHsgYjogaTMyID0gdGhpcy5hICogMTA7IGNvbnN0cnVjdG9yKCkgeyBzdXBlcig1KTsgfSB9CmV4cG9ydCBmdW5jdGlvbiBmKCk6IGkzMiB7IHJldHVybiBuZXcgQigpLmI7IH0gLy8gZXhwZWN0ZWQgNTAKCmV4cG9ydCBmdW5jdGlvbiBnKCk6IGkzMiB7CiAgY29uc3QgYTogaTMyW10gPSBbMSwgMiwgMywgNF07CiAgYS5maWxsKDcsIC05KTsgLy8gZXhwZWN0ZWQgWzcsIDcsIDcsIDddCiAgX19jb2xsZWN0KCk7CiAgcmV0dXJuIGFbMF07Cn0KCmV4cG9ydCBmdW5jdGlvbiBoKCk6IGkzMiB7CiAgY29uc3QgYTogaTMyW10gPSBbMSwgMiwgM107CiAgYS5jb3B5V2l0aGluKDEsIDIsIDEpOyAvLyBleHBlY3RlZCBuby1vcAogIHJldHVybiBhLmxlbmd0aDsKfQojIWh0bWwKPHRleHRhcmVhIGlkPSJvdXRwdXQiIHN0eWxlPSJoZWlnaHQ6IDEwMCU7IHdpZHRoOiAxMDAlIiByZWFkb25seT48L3RleHRhcmVhPgo8c2NyaXB0PgooYXN5bmMgKCkgPT4gewogIGNvbnN0IG91dCA9IGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCJvdXRwdXQiKTsKICBmb3IgKGNvbnN0IG4gb2YgWyJmIiwgImgiLCAiZyJdKSB7CiAgICBjb25zdCBleHBvcnRzID0gYXdhaXQgaW5zdGFudGlhdGUoYXdhaXQgY29tcGlsZSgpLCB7fSk7CiAgICB0cnkgeyBvdXQudmFsdWUgKz0gbiArICIgPSAiICsgZXhwb3J0c1tuXSgpICsgIlxuIjsgfSBjYXRjaCAoZSkgeyBvdXQudmFsdWUgKz0gbiArICIgdGhyZXcgIiArIGUubWVzc2FnZSArICJcbiI7IH0KICB9Cn0pKCk7Cjwvc2NyaXB0Pgo=\n\n### AssemblyScript version\n\nv0.28.20 (main b6bda05c)\n\nCredit: https://ucsbplse.github.io/\n","author":{"url":"https://github.com/trackoor","@type":"Person","name":"trackoor"},"datePublished":"2026-11-09T23:21:45Z","url":"https://github.com/AssemblyScript/assemblyscript/issues/3064"}
| 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:b0f2f6da-cf8f-cc23-fe9e-87d0c3adb43d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | ED90:15E5F9:298250F:38C495C:6B0051D6 |
| html-safe-nonce | 335fec1a2730e2a0d498350ec9ffef24533434eb194ad87fb6cb7f07ba343024 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFRDkwOjE1RTVGOToyOTgyNTBGOjM4QzQ5NUM6NkIwMDUxRDYiLCJ2aXNpdG9yX2lkIjoiOTA4ODQ4NzcwMzI5MDMxMjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 612f641fb7e1710ae621a742840047ed17350aa8501f689a06d9f864ea84a996 |
| hovercard-subject-tag | issue:6296719667 |
| 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/3064/issue_layout |
| twitter:image | https://opengraph.githubassets.com/58dabd706198309176b85e8d53d8666b876325ed4fc9bfbc1a1e3b18b43eabaf/AssemblyScript/assemblyscript/issues/3064 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/58dabd706198309176b85e8d53d8666b876325ed4fc9bfbc1a1e3b18b43eabaf/AssemblyScript/assemblyscript/issues/3064 |
| og:image:alt | Bug description Three differences from TypeScript/JavaScript semantics inside the documented subset (same results with -O0 and -O3): Field initializers of a derived class with an explicit construct... |
| 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