Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
saharan opened this issue Apr 8, 2022 · 1 comment · Fixed by #11967
Closed

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

saharan opened this issue Apr 8, 2022 · 1 comment · Fixed by #11967
Milestone

Comments

@saharan
Copy link
Contributor

saharan commented Apr 8, 2022

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

@Simn Simn added this to the Later milestone Mar 24, 2023
@RblSb
Copy link
Member

RblSb commented May 10, 2023

Fixed in 4.3
Project: complextype_pos.zip

kLabz added a commit that referenced this issue Feb 4, 2025
kLabz added a commit that referenced this issue Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants