January 06, 2022

I can't figure out why this code works:

union A {
	int* b;
	float c;
}

int fun(A a) @safe {
	return *(()=>a.b)();
	// return *a.b; //Complains about pointer type overlap
}

I tried to find out how @safe should be handled in this scenario, and found lambda's could be denoted as @trusted, but this even works without a @trusted denotation. Am I missing something?

January 06, 2022

On Thursday, 6 January 2022 at 16:12:10 UTC, HuskyNator wrote:

>

I can't figure out why this code works:

union A {
	int* b;
	float c;
}

int fun(A a) @safe {
	return *(()=>a.b)();
	// return *a.b; //Complains about pointer type overlap
}

I tried to find out how @safe should be handled in this scenario, and found lambda's could be denoted as @trusted, but this even works without a @trusted denotation. Am I missing something?

This is a known bug in the compiler's inference of the @safe attribute.

Looks like the fix is currently blocked due to other issues.