serve-d icon indicating copy to clipboard operation
serve-d copied to clipboard

Code action to add @safe/trusted/system

Open WebFreak001 opened this issue 4 years ago • 0 comments

The errors

file.d(n): Error: @safe function <func> cannot call @system function <func>

and

file.d(n): Error: <anything> not allowed in safe code

should have code actions to fix.

Example:

void safeFunc()
{
	<unsafe erroring stuff>
}

should suggest, when on the error:

  • Mark function as @system
  • Mark call as @trusted

Mark function as @system should do the obvious:

void safeFunc() @system
{
	<unsafe erroring stuff>
}

Mark call as @trusted should do one the following:

unsafe erroring stuff is a single statement:

void safeFunc() @system
{
	(() @trusted => <unsafe erroring stuff>)();
}

unsafe erroring stuff is a block of statements: (wouldn't actually be used for now because it only acts by error messages which is gonna be at most a statement)

void safeFunc() @system
{
	(() @trusted {
		<unsafe erroring stuff>
	})();
}

WebFreak001 avatar Jan 02 '20 20:01 WebFreak001