Untagged variant with Blob and File cases never matches File when Blob is declared first
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- javascript
- Domain
- compilers
Research direction
Start with compiler/ml/ast_untagged_variants.ml, especially type_to_instanceof_backed_obj, and trace how untagged variant cases become ordered instanceof checks. Check the compiler tests for untagged variants and add coverage for File and Blob in both declaration orders. Done means the subclass case is matched first regardless of order, or the unsupported variant is rejected.
Written by the indexing model from the issue text.
Description
An untagged variant with cases for a class and one of its subclasses tests them in declaration order, so the subclass case can never match when it is declared second:
@unboxed
type upload = Blob(Blob.t) | File(File.t)
let describe = u =>
switch u {
| Blob(_) => "blob"
| File(_) => "file"
}
compiles to
function describe(u) {
if (u instanceof Blob) {
return "blob";
} else {
return "file";
}
}
File extends Blob, so for File(new File(["x"], "a.txt")) the check u instanceof Blob is true and describe returns "blob" (checked in Node). Declaring File(File.t) | Blob(Blob.t) instead emits u instanceof File and works, whatever the order of the switch cases.
Expected: a subclass is tested before its superclass regardless of declaration order, or the variant is rejected.
Cause: type_to_instanceof_backed_obj in compiler/ml/ast_untagged_variants.ml maps a fixed list of stdlib type names to classes but records no relation between them, so the tests are emitted in declaration order. File/Blob is the only subclass pair in that list today. The same question comes up for user-declared classes (e.g. HTMLElement extends Element) if bindings can declare their runtime class.
Reproduced on current master.
- Dominant language
- ReScript
- Stars
- 7.5k
- Forks
- 483
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 164
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing 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.
More from rescript-lang/rescript
-
discussion enhancement
Difficulty 5/5 Over a week Newbie friendliness 35/100
rescript-lang/rescript#8934 · 1 reaction ·
Maintainers usually reply within 1 day
-
Partial application moves its arguments into the generated closurePossibly taken @cknitt claimed this 1 day ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 25/100
rescript-lang/rescript#8932 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
rescript-lang/rescript#8910 ·
Maintainers usually reply within 1 day
-
Nested JSX components under React Server Components: derive flat exports from the signaturePossibly taken @cknitt claimed this 3 days ago. Open
Difficulty 5/5 Over a week Newbie friendliness 25/100
rescript-lang/rescript#8901 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
rescript-lang/rescript#8897 ·
Maintainers usually reply within 1 day
All issues in rescript-lang/rescript
Similar issues
-
bug priority: P2
Difficulty 1/5 Under an hour Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
confirmed generated by fuzzer llvm:optimizations miscompilation
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
llvm/llvm-project#234325 ·
Maintainers usually reply within 1 day
-
grammar selfhost sev-3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
gren-lang/compiler-common#41 ·