diff --git a/tests/display/build.hxml b/tests/display/build.hxml index f9eccc98b2b..aea471ff030 100644 --- a/tests/display/build.hxml +++ b/tests/display/build.hxml @@ -2,4 +2,4 @@ --main Main --interp -D use-rtti-doc -# -D test=Issue7326 \ No newline at end of file +# -D test=Issue7877 diff --git a/tests/display/src/Diagnostic.hx b/tests/display/src/Diagnostic.hx new file mode 100644 index 00000000000..05f8534788e --- /dev/null +++ b/tests/display/src/Diagnostic.hx @@ -0,0 +1,29 @@ +// from vshaxe + +import haxe.display.Position.Range; + +enum abstract UnresolvedIdentifierSuggestion(Int) { + var UISImport; + var UISTypo; +} + +enum abstract DiagnosticKind(Int) from Int to Int { + var DKUnusedImport:DiagnosticKind; + var DKUnresolvedIdentifier:DiagnosticKind>; + var DKCompilerError:DiagnosticKind; + var DKRemovableCode:DiagnosticKind<{description:String, range:Range}>; +} + +enum abstract DiagnosticSeverity(Int) { + var Error = 1; + var Warning; + var Information; + var Hint; +} + +typedef Diagnostic = { + var kind:DiagnosticKind; + var range:Range; + var severity:DiagnosticSeverity; + var args:T; +} diff --git a/tests/display/src/DisplayTestCase.hx b/tests/display/src/DisplayTestCase.hx index 4de57d2e35c..60bd38d675e 100644 --- a/tests/display/src/DisplayTestCase.hx +++ b/tests/display/src/DisplayTestCase.hx @@ -20,6 +20,7 @@ class DisplayTestCase { inline function range(pos1, pos2) return ctx.range(pos1, pos2); inline function signature(pos1) return ctx.signature(pos1); inline function metadataDoc(pos1) return ctx.metadataDoc(pos1); + inline function diagnostics() return ctx.diagnostics(); inline function noCompletionPoint(f) return ctx.noCompletionPoint(f); @@ -35,20 +36,20 @@ class DisplayTestCase { } } - function arrayEq(expected:Array, actual:Array, ?pos:haxe.PosInfos) { + function arrayEq(expected:Array, actual:Array, ?pos:haxe.PosInfos) { numTests++; var leftover = expected.copy(); for (actual in actual) { if (!leftover.remove(actual)) { numFailures++; report("Result not part of expected Array:", pos); - report(actual, pos); + report(Std.string(actual), pos); } } for (leftover in leftover) { numFailures++; report("Expected result was not part of actual Array:", pos); - report(leftover, pos); + report(Std.string(leftover), pos); return; } } diff --git a/tests/display/src/DisplayTestContext.hx b/tests/display/src/DisplayTestContext.hx index dfaaac1f66a..ba23e4f2555 100644 --- a/tests/display/src/DisplayTestContext.hx +++ b/tests/display/src/DisplayTestContext.hx @@ -77,6 +77,11 @@ class DisplayTestContext { return extractMetadata(callHaxe('$pos@type')); } + public function diagnostics():Array> { + var result = haxe.Json.parse(callHaxe('0@diagnostics'))[0]; + return if (result == null) [] else result.diagnostics; + } + public function noCompletionPoint(f:Void -> Void):Bool { return try { f(); diff --git a/tests/display/src/cases/Issue7877.hx b/tests/display/src/cases/Issue7877.hx new file mode 100644 index 00000000000..3fec68de03c --- /dev/null +++ b/tests/display/src/cases/Issue7877.hx @@ -0,0 +1,15 @@ +package cases; + +class Issue7877 extends DisplayTestCase { + /** + class Main { + public static function main() { + new misc.issue7877.ProcessedClass(false); + new misc.issue7877.ProcessedClass(true); + } + } + **/ + function test() { + arrayEq([], diagnostics()); + } +} diff --git a/tests/display/src/misc/issue7877/ProcessMacro.hx b/tests/display/src/misc/issue7877/ProcessMacro.hx new file mode 100644 index 00000000000..d957b44876d --- /dev/null +++ b/tests/display/src/misc/issue7877/ProcessMacro.hx @@ -0,0 +1,40 @@ +package misc.issue7877; + +import haxe.macro.Expr; +import haxe.macro.Context; + +class ProcessMacro { + public static macro function build():Array { + var fields = Context.getBuildFields(); + var toInit = [ + for (field in fields) { + switch (field) { + case {name: name, kind: FVar(t, e), access: [AFinal]}: + {name: name, type: t, def: e}; + case _: + continue; + } + } + ]; + + var args:Array = []; + var exprs = []; + for (init in toInit) { + args.push({ + name: init.name, + opt: init.def != null, + type: init.type, + value: init.def + }); + var n = init.name; + exprs.push(macro this.$n = $i{n}); + } + fields.push({ + pos: Context.currentPos(), + name: 'new', + access: [APublic], + kind: FFun({ret: null, args: args, expr: {pos: Context.currentPos(), expr: EBlock(exprs)}}) + }); + return fields; + } +} diff --git a/tests/display/src/misc/issue7877/ProcessedClass.hx b/tests/display/src/misc/issue7877/ProcessedClass.hx new file mode 100644 index 00000000000..2f8e571ee86 --- /dev/null +++ b/tests/display/src/misc/issue7877/ProcessedClass.hx @@ -0,0 +1,9 @@ +package misc.issue7877; + +@:build(misc.issue7877.ProcessMacro.build()) class ProcessedClass { + final foo:Bool; // = false; + + function bar() { + trace(foo); + } +}