microsoft / microsoft/pxt-microbit
Abstract TypeScript methods do not work
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 804
- Forks
- 721
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 2
Description
Describe the bug
When extending an abstract class with an abstract method, the pxt build fails.
To Reproduce
Run pxt build for the program below.
abstract class AbstractPlayer {
abstract play(): void
}
class Player extends AbstractPlayer {
play(): void {
music.play(music.tonePlayable(262, music.beat(BeatFraction.Whole)), music.PlaybackMode.UntilDone)
}
}
const player = new Player()
player.play()
The compilation fails with
INTERNAL ERROR: Error: Assertion failed
at Object.assert (/Users/pavel/Git/Microbit/makecode/node_modules/pxt-core/built/pxt.js:98695:27)
at getVTable (/Users/pavel/Git/Microbit/makecode/node_modules/pxt-core/built/pxt.js:133474:32)
at emitVTables (/Users/pavel/Git/Microbit/makecode/node_modules/pxt-core/built/pxt.js:134517:21)
at Object.compileBinary (/Users/pavel/Git/Microbit/makecode/node_modules/pxt-core/built/pxt.js:133162:13)
at Object.compile (/Users/pavel/Git/Microbit/makecode/node_modules/pxt-core/built/pxt.js:137199:40)
at /Users/pavel/Git/Microbit/makecode/node_modules/pxt-core/built/pxt.js:165353:21
make: *** [build] Error 20
When changing the AbstractPlayer to
abstract class AbstractPlayer {
play(): void {}
}
The compilation succeeds and the code works well on micro:bit.
Expected behavior
The compilation should succeed.
Desktop (please complete the following information):
- OS: macOS Sequoia 15.1.1
- target: v7.1.15
- pxt-core v11.3.3
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with the abstract TypeScript example by running pxt build on the micro:bit target. Start from the reported getVTable and emitVTables paths in pxt-core/built/pxt.js, then compare them with the successful concrete-method variant. Done means the abstract-method program compiles and runs without the assertion failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100