HaxeFoundation / HaxeFoundation/haxe

Malformed `haxe.macro.Type` crashes `Context.followWithAbstracts`

Open
#10,959 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

Might be a bit silly, but was stuck for a while on a compiler crash from complex macro code that was the result of a malformed `haxe.macro.Type`.

Passing a `TAbstract(t:Ref, params:Array)` with an empty "params" array for an abstract that required type parameters to `Context.followWithAbstracts` causes a crash.

Haxe Crash Report

Compiler failure

Please submit an issue at https://github.com/HaxeFoundation/haxe/issues/new
Attach the following information:
Haxe: 4.2.5; OS type: windows;
File "src/core/tFunctions.ml", line 334, characters 16-23
Called from file "src/core/tFunctions.ml", line 336, characters 13-32
Called from file "src/core/abstract.ml", line 148, characters 17-54
Called from file "src/core/abstract.ml", line 152, characters 24-50
Called from file "src/macro/macroApi.ml", line 1838, characters 64-96
Called from file "src/macro/eval/evalMain.ml", line 377, characters 4-8
Called from file "src/macro/eval/evalEmitter.ml", line 747, characters 9-17
Called from file "src/macro/eval/evalEmitter.ml", line 747, characters 9-17
Called from file "src/macro/eval/evalEmitter.ml", line 183, characters 35-48
Called from file "src/macro/eval/evalEmitter.ml", line 191, characters 6-48
Called from file "src/macro/eval/evalEmitter.ml", line 747, characters 9-17
Called from file "src/macro/eval/evalExceptions.ml", line 99, characters 5-8
Called from file "src/macro/eval/evalExceptions.ml", line 114, characters 10-38
Called from file "src/macro/eval/evalMisc.ml", line 263, characters 21-79
Called from file "src/macro/macroApi.ml", line 1640, characters 44-88
Called from file "src/typing/macroContext.ml", line 181, characters 4-50
Called from file "list.ml", line 106, characters 12-15
Called from file "src/filters/filters.ml", line 797, characters 1-66
Called from file "src/compiler/haxe.ml", line 611, characters 1-26
Called from file "src/compiler/haxe.ml", line 1078, characters 2-39
Called from file "src/compiler/haxe.ml", line 642, characters 3-11
File "src/core/globals.ml", line 117, characters 1-7: Assertion failed

Maybe a bit niche of an issue, but would be nice if there were a `Context` function to validate `haxe.macro.Type`s before being passed to the compiler internals?

Minimal replication:
```haxe
// --macro MacroThing.start()
class MacroThing {
public static function start() {
haxe.macro.Context.onGenerate(function(types: Array) {
for(t in types) makeMalformedType(t);
});
}

static function makeMalformedType(t: haxe.macro.Type) {
switch(t) {
case TAbstract(a, _): {
// Crashes upon encountering abstract type that requires
// type parameter.
haxe.macro.Context.followWithAbstracts(TAbstract(a, []));
}
case _: {}
}
}
}

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.