haxe icon indicating copy to clipboard operation
haxe copied to clipboard

Obscure deprecation warning

Open RblSb opened this issue 7 months ago • 2 comments

If i use new WebSocket (hxnodejs-ws) that depends on Url (from hxnodejs), i get deprecation warning about Url function that is not used, but has deprecated typedef in overload. There is no information how that Url.format is called from user code.

import haxe.extern.EitherType;

class Main {
	static function main() {
		final ws = new WebSocket("");
	}
}

class WebSocket {
	public function new(address:EitherType<String, Url>) {};
}

class Url {
	// (WDeprecated) This typedef is deprecated in favor of { }
	@:overload(function(urlObject:UrlObject):String {})
	static function format(url:String):String {
		return "";
	}
}

@:deprecated
typedef UrlObject = {};

RblSb avatar Apr 11 '25 20:04 RblSb

I've dug up the commit that checked typedef deprecation during typing: https://github.com/HaxeFoundation/haxe/commit/0eb30bd35509940a84f385c2a7352309aa007086

Unfortunately, it doesn't mention why I did that. The situation with overloads is a bit awkward because we indeed type the deprecated module type while trying out overloads, so I understand why the deprecation warning occurs. I'll see if removing this early check breaks any tests.

Edit: It breaks the test for #4720 like so:

Running haxe projects/Issue4720/compile.hxml
-Main.hx:8: characters 9-15 : Warning : (WDeprecated) Usage of this typedef is deprecated
-Main.hx:9: characters 9-19 : Warning : (WDeprecated) Usage of this typedef is deprecated
-Main.hx:10: characters 9-14 : Warning : (WDeprecated) Usage of this typedef is deprecated
 Main.hx:18: characters 13-19 : Warning : (WDeprecated) This typedef is deprecated in favor of MyClass   
-Main.hx:19: characters 9-14 : Warning : (WDeprecated) Usage of this typedef is deprecated
 Main.hx:20: characters 13-22 : Warning : (WDeprecated) This typedef is deprecated in favor of MyAbstract
 Main.hx:32: characters 9-13 : Warning : (WDeprecated) Usage of this enum is deprecated
 Main.hx:36: characters 9-14 : Warning : (WDeprecated) Usage of this enum field is deprecated
 Main.hx:4: characters 9-16 : Warning : (WDeprecated) Usage of this class is deprecated
 Main.hx:5: characters 9-20 : Warning : (WDeprecated) Usage of this class is deprecated
 Main.hx:6: characters 9-15 : Warning : (WDeprecated) Usage of this enum is deprecated
+Main.hx:8: characters 9-15 : Warning : (WDeprecated) Usage of this class is deprecated
+Main.hx:9: characters 9-19 : Warning : (WDeprecated) Usage of this class is deprecated
+Main.hx:10: characters 9-14 : Warning : (WDeprecated) Usage of this enum is deprecated
 Main.hx:15: characters 9-22 : Warning : (WDeprecated) Usage of this class is deprecated
 Main.hx:16: characters 9-15 : Warning : (WDeprecated) Usage of this enum is deprecated
 Main.hx:17: characters 9-29 : Warning : (WDeprecated) Usage of this class is deprecated
 Main.hx:18: characters 9-21 : Warning : (WDeprecated) Usage of this class is deprecated
+Main.hx:19: characters 9-14 : Warning : (WDeprecated) Usage of this enum is deprecated
 Main.hx:20: characters 9-28 : Warning : (WDeprecated) Usage of this class is deprecated
 Main.hx:23: characters 9-24 : Warning : (WDeprecated) Usage of this field is deprecated
 Main.hx:24: characters 9-23 : Warning : (WDeprecated) Usage of this field is deprecated
 Main.hx:25: characters 9-27 : Warning : (WDeprecated) Usage of this field is deprecated
 Main.hx:26: characters 17-35 : Warning : (WDeprecated) Usage of this field is deprecated
 Main.hx:27: characters 9-25 : Warning : (WDeprecated) Usage of this field is deprecated
 Main.hx:28: characters 17-33 : Warning : (WDeprecated) Usage of this field is deprecated
 Main.hx:31: characters 11-15 : Warning : (WDeprecated) Usage of this enum is deprecated
 Main.hx:35: characters 11-16 : Warning : (WDeprecated) Usage of this enum field is deprecated

If I'm reading that correctly (four - and four +) this merely changes the order though, which would be expected.

Edit: I'm wrong (and the test sucks). They all go from "this typedef" to "this class" or "this enum", which means the check is indeed lost and the line only shows up because the typedeffed type is also deprecated.

Simn avatar Apr 12 '25 08:04 Simn

So this check is needed for this very simple case:

class C {}

@:deprecated
typedef T = C;

function main() {
	trace(T);
}

The generated AST doesn't have T anywhere:

	public static function main[Function:() -> Void]
		[Block:Void]
			[Call:Void]
				[Ident:Dynamic] `trace
				[TypeExpr C:Class<C>]
				[ObjectDecl:{ methodName : String, lineNumber : Int, fileName : String, className : String }]
					fileName: [Const:String] "source/Main.hx"
					lineNumber: [Const:Int] 7
					className: [Const:String] "_Main.Main_Fields_"
					methodName: [Const:String] "main"

So the only chance to detect this is during typing itself. Which also means that I don't know how to fix this in the context of overloads.

Simn avatar Apr 12 '25 08:04 Simn