Skip to content

Arrays.count fails when used in macros #293

@tkwiatek

Description

@tkwiatek

Description

@:generic methods fails when used in macros

Code examples

Direct use with thx import

using thx.Arrays;
class Test {
	static function main() {
		trace(checkCount());
	}

	macro static function checkCount() {
		final arr = ['a', 'b', 'b', 'c', 'c', 'c', 'd', 'd', 'd', 'd'];
		final count = thx.Arrays.count(arr);
		return haxe.macro.Context.makeExpr(count, haxe.macro.Context.currentPos());
	}
}

fails with:

[ERROR] (unknown position)
   | Field index for count_String not found on prototype thx.Arrays

Direct use with thx import (but different class)

using thx.Strings;
class Test {
	static function main() {
		trace(checkCount());
	}

	macro static function checkCount() {
		final arr = ['a', 'b', 'b', 'c', 'c', 'c', 'd', 'd', 'd', 'd'];
		final count = thx.Arrays.count(arr);
		return haxe.macro.Context.makeExpr(count, haxe.macro.Context.currentPos());
	}
}

fails with:

[ERROR] (unknown position)
   | Field index for count_String not found on prototype thx.Arrays

import + static extension

using thx.Arrays;
class Test {
	static function main() {
		trace(checkCount());
	}

	macro static function checkCount() {
		final arr = ['a', 'b', 'b', 'c', 'c', 'c', 'd', 'd', 'd', 'd'];
		final count = arr.count();
		return haxe.macro.Context.makeExpr(count, haxe.macro.Context.currentPos());
	}
}

fails with:

[ERROR] (unknown position)
   | Field index for count_String not found on prototype thx.Arrays

direct use without import

class Test {
	static function main() {
		trace(checkCount());
	}

	macro static function checkCount() {
		final arr = ['a', 'b', 'b', 'c', 'c', 'c', 'd', 'd', 'd', 'd'];
		final count = thx.Arrays.count(arr);
		return haxe.macro.Context.makeExpr(count, haxe.macro.Context.currentPos());
	}
}

success:

Test.hx:4:,[d => 4,c => 3,b => 2,a => 1]

Expected behavior

Method works direct and as static extension in macros, when importing any thx class

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions