Skip to content

[macro][display] Setting ComplexType to Field breaks Position data #10673

@saharan

Description

@saharan

ComplexTypes in parsed ASTs seem to have hidden position data, and modifying them in a particular way will result in broken position data, which prevents completions in IDE and causes wrong hover displays.

PosTest.hx

@:build(PosBuild.build())
class PosTest {
	var a:Int;

	function func1():Void {
		var lhs_______ = 0;
		var rhs_______ = 0;
		lhs_______ = rhs_______;
		lhs_______ = rhs_______;
		lhs_______ = rhs_______;
		lhs_______ = rhs_______;
		lhs_______ = rhs_______;
		lhs_______ = rhs_______;
		lhs_______ = rhs_______;
		lhs_______ = rhs_______;
	}
}

PosBuild.hx

#if macro
import haxe.macro.Expr;
import haxe.macro.Context;

using haxe.macro.ComplexTypeTools;
using haxe.macro.TypeTools;

class PosBuild {
	macro function build():Array<Field> {
		final fields = Context.getBuildFields();
		for (field in fields) {
			switch field.kind {
				case FVar(_, e):
					field.kind = FVar(TPath({
						pack: ["std"],
						name: "StdTypes",
						sub: "Int"
					}), e);
				case _:
			}
		}
		return fields;
	}
}
#end

Hovering this item is fine:

@:build(PosBuild.build())
class PosTest {
	var a:Int;

	function func1():Void {
		var lhs_______ = 0;
		var rhs_______ = 0;
		lhs_______ = rhs_______;
		lhs_______ = rhs_______;
		lhs_______ = rhs_______;
		lhs_______ = rhs_______;
		lhs_______ = rhs_______;
		lhs_______ = rhs_______;
		lhs_______ = [rhs_______];
		lhs_______ = rhs_______;
	}
}

But hovering this item will result in the wrong display:

@:build(PosBuild.build())
class PosTest {
	var a:Int;

	function func1():Void {
		var lhs_______ = 0;
		var rhs_______ = 0;
		lhs_______ = rhs_______;
		lhs_______ = rhs_______;
		lhs_______ = rhs_______;
		lhs_______ = rhs_______;
		lhs_______ = rhs_______;
		lhs_______ = rhs_______;
		lhs_______ = rhs_______;
		lhs_______ = [rhs_______];
	}
}

Like this:
image

This also prevents any completion trial from the point.
image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions