Page MenuHomeFeedback Tracker

Static array initializer unable to distinguish overloads
Closed, ResolvedPublic

Description

If the static array initializer is used to create a multi-level array or complex types that accept arrays then the compiler is unable to decide which overload he should use.

Given this class

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

This code

ReproduceItem.From({1, 2, 3});
ReproduceItem.From({1.1, 2.2, 3.3});

Results in

SCRIPT : Compiling Game scripts
SCRIPT (E): @"Scripts/Game/test.c,50": Array initialization of non-array type
SCRIPT (E): @"Scripts/Game/test.c,51": Array initialization of non-array type
SCRIPT (E): Can't compile "Game" script module!

Scripts/Game/Core/test.c(50): Array initialization of non-array type

The game does know which type the array is. If you try to pass an int static init array into string array etc., then it complains about incompatible types at compile time already.


The only workaround right now seems to be adding a stong type wrapper like this:

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

And then call

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

which is not really a desired way of handling it.

Details

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

Event Timeline

Arkensor updated the task description. (Show Details)
Arkensor renamed this task from Static array initalizer unable to distinguish overloads to Static array initializer unable to distinguish overloads.Jul 27 2022, 11:54 AM
Ralian added a subscriber: Ralian.Jul 28 2022, 7:23 PM

Arkensor, you're not going to like this because of how broken implicit casting is in EnfScript, but here is another workaround :)

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

ReproduceItem.From((TIntArray){1, 2, 3});
ReproduceItem.From((TFloatArray){1.1, 2.2, 3.3});

This makes the type resolution work, and I know it compiles and runs without crashing. I have not debugged it extensively however.

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:42 PM
Geez claimed this task.
Geez added a subscriber: Geez.

Will be fixed in one of the future updates.