Beef icon indicating copy to clipboard operation
Beef copied to clipboard

Generic types that call it's own comptime methods will execute with unspecialized parameters, causing errors

Open elusivePorpoise opened this issue 8 months ago • 0 comments

Image

class RangeConstraint<TNum, TRange> 
	where TNum : const int
	where TRange : const ClosedRange
{
	struct Ok;
	public typealias Res = comptype(Check());

        // Workaround: uncomment following
	//public static bool Contains(Object range, int num) => false;
	//public static bool Contains(ClosedRange range, int num) => range.Contains(num);

	[Comptime]
	static Type Check()
	{
                // Workaround: uncomment following
                // if (!Contains(TRange, TNum))
                //     return typeof(void);               
		if (!TRange.Contains(TNum)) // Workaround: comment out
		        return typeof(void);// Workaround: comment out 
		return typeof(Ok);
	}
}

After workaround, IDE falsely reports errors (on and off) when working in a file containing the code

elusivePorpoise avatar Mar 29 '25 10:03 elusivePorpoise