Page MenuHomeFeedback Tracker

Cast error on static static array initializer syntax
Closed, ResolvedPublic

Description

There is a strange compile error happening on the script scenario below. Somewhat related to Static array initializer unable to distinguish overloads, but likely a separate issue.

class StrongTypedArray<Class T>
{
	static array<T> From(notnull array<T> values)
	{
		return values;
	}
}

class ReproduceItem
{
	static ReproduceItem From(array<int> integers)
	{
	}
	
	static ReproduceItem From(array<float> floats)
	{
	}
	
	static ReproduceItem From(array<bool> bools)
	{
	}
}

class ReproduceContainer
{
	static ReproduceContainer From(array<ReproduceItem> items)
	{
	}
}

void ReproduceTheIssue()
{
	ReproduceContainer container = ReproduceContainer.From({
		ReproduceItem.From(StrongTypedArray<int>.From({1, 2, 3})),
		ReproduceItem.From(StrongTypedArray<float>.From({1.1, 2.2, 3.3})),
	});
}

The code above when trying to compile results in:

SCRIPT (E): @"Scripts/Game/test.c,33": Unsafe down-casting, use 'array<ReproduceItem>.Cast' for safe down-casting

It is worth mentioning that the error "disappears" after a code change to this - removing the return value. it also only happens when this strong array type wrapper is used. In other scenarios, I did not experience any problems with the static initializer in general.

class StrongTypedArray<Class T>
{
	static array<T> From(notnull array<T> values)
	{
		//return values;
	}
}

Edit:
Adding a typedef or using the exact StrongTypedArray template variant used in the static initializer seems to make the code work as well e.g.

typedef StrongTypedArray<int> a;
typedef StrongTypedArray<float> b;
...
StrongTypedArray<int> hello();
StrongTypedArray<float> hello2();

This might indicate that the issue is related to the template not being found and thus it tries to init with invalid type and that is why he thinks he needs to cast?

Details

Severity
Major
Resolution
Open
Reproducibility
Always
Operating System
Windows 10 x64
Category
General

Event Timeline

Arkensor updated the task description. (Show Details)Jul 27 2022, 1:24 PM
Geez changed the task status from New to Assigned.Aug 8 2022, 11:00 PM
Geez closed this task as Resolved.Apr 26 2023, 2:35 PM
Geez claimed this task.
Geez added a subscriber: Geez.

Fixed for one of the future updates.