-
-
Notifications
You must be signed in to change notification settings - Fork 657
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[4.3.6] Context.reportError should not abort build macros (#11741)
* [macro] flush pass before altering error reporting * [tests] add test showing Context.reportError vs build macro issue
- Loading branch information
Showing
6 changed files
with
79 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
import haxe.macro.Expr.Field; | ||
import haxe.macro.Context; | ||
|
||
class Macro { | ||
public static macro function buildMain(): Array<Field> { | ||
final pos = Context.currentPos(); | ||
final bf = Context.getBuildFields(); | ||
|
||
final type = Context.getType('Test2'); | ||
|
||
switch (type) { | ||
case TInst(ctRef, _): | ||
final ct = ctRef.get(); | ||
|
||
try { | ||
final ctor = ct.constructor.get().expr(); | ||
} catch (e: Dynamic) { | ||
|
||
} | ||
|
||
Context.warning('This does not show if printStuff() calls error() or reportError()', pos); | ||
case _: | ||
} | ||
|
||
return bf; | ||
} | ||
|
||
public static macro function buildTest2(): Array<Field> { | ||
final pos = Context.currentPos(); | ||
final bf = Context.getBuildFields(); | ||
|
||
// Use error() or reportError() here -> Main Completion does not work, Eval crashes | ||
// Use warning() or info() -> Everything works as expected | ||
Context.reportError('Crashes HERE in eval.vm.callMacroApi', pos); | ||
|
||
return bf; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Should be a warning here, UNLESS Macro.printStuff() calls reportError()/error() | ||
@:build(Macro.buildMain()) | ||
class Main { | ||
static function main() { | ||
final x = 5 - ""; // No errors shown for this, completion/hover does not work | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
@:autoBuild(Macro.buildTest2()) | ||
class Test2 { | ||
public function new(a: Int, b: Int) {} | ||
} | ||
|
||
class Test2Ext extends Test2 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--main Main | ||
-D message.reporting=pretty | ||
-D message.no-color |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[ERROR] Test2.hx:7: character 1 | ||
|
||
7 | class Test2Ext extends Test2 {} | ||
| ^ | ||
| Crashes HERE in eval.vm.callMacroApi | ||
|
||
[WARNING] Main.hx:2: characters 1-8 | ||
|
||
2 | @:build(Macro.buildMain()) | ||
| ^^^^^^^ | ||
| This does not show if printStuff() calls error() or reportError() | ||
|
||
[ERROR] Main.hx:5: characters 19-21 | ||
|
||
5 | final x = 5 - ""; // No errors shown for this, completion/hover does not work | ||
| ^^ | ||
| String should be Int | ||
|