On Monday, 18 July 2022 at 18:01:45 UTC, Ola Fosheim Grøstad wrote:
> On Monday, 18 July 2022 at 17:45:08 UTC, FeepingCreature wrote:
> Spurious compiler errors, fine, but a compiler update should not cause a very basic construct like [] to start corrupting values.
But this is more of a development process and quality assurance issue than a language design issue.
The former should adapt to the latter, not the other way around…
I have made a Renderer abstraction, so, in OpenGL terms I have been setting my Uniform variables such as Vector2
, Vector3
, Vector4
. But importing math.vector
for just setting those variables creates unnecessary dependency, what have I done to solve this problem?
void setUniform(string uniformName, float[2] vec);
void setUniform(string uniformName, float[3] vec);
void setUniform(string uniformName, float[4] vec);
What happens if I do:
void setupRenderer() @nogc
{
setUniform("Test", [1, 2]);
setUniform("Test", [1, 2, 3]);
setUniform("Test", [1, 2, 3, 4]);
}
Then what it happens?
Error: @nogc
function setupRenderer
cannot call non-@nogc function renderer.setUniform
Error: @nogc
function setupRenderer
cannot call non-@nogc function renderer.setUniform
Error: @nogc
function setupRenderer
cannot call non-@nogc function renderer.setUniform
You guys solution:
import std.array;
void setupRenderer() @nogc
{
setUniform("Test", [1, 2].staticArray);
setUniform("Test", [1, 2, 3].staticArray);
setUniform("Test", [1, 2, 3, 4].staticArray);
}
Unnecessary verbosity. That's all I could say. Then, what happens?
onlineapp.d(29): Error: none of the overloads of `setUniform` are callable using argument types `(string, int[2])`
onlineapp.d(13): Candidates are: `onlineapp.setUniform(string uniformName, float[2] vec)`
onlineapp.d(17): `onlineapp.setUniform(string uniformName, float[3] vec)`
onlineapp.d(21): `onlineapp.setUniform(string uniformName, float[4] vec)`
onlineapp.d(30): Error: none of the overloads of `setUniform` are callable using argument types `(string, int[3])`
onlineapp.d(13): Candidates are: `onlineapp.setUniform(string uniformName, float[2] vec)`
onlineapp.d(17): `onlineapp.setUniform(string uniformName, float[3] vec)`
onlineapp.d(21): `onlineapp.setUniform(string uniformName, float[4] vec)`
onlineapp.d(31): Error: none of the overloads of `setUniform` are callable using argument types `(string, int[4])`
onlineapp.d(13): Candidates are: `onlineapp.setUniform(string uniformName, float[2] vec)`
onlineapp.d(17): `onlineapp.setUniform(string uniformName, float[3] vec)`
onlineapp.d(21):
So, for solving that, one must either:
setUniform("Test", [cast(float)1, 2].staticArray);
Or they need to actually have a float literal in the array.
Actually, I think that could be one of the the worse usecases for that