Bug 19235 – Repeatedly calling non-pure function in non-pure literal nested in pure function is broken
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-09-08T12:38:18Z
Last change time
2023-04-28T11:14:56Z
Assigned to
No Owner
Creator
Johannes Pfau
Comments
Comment #0 by johannespfau — 2018-09-08T12:38:18Z
The test case is much simpler than the title:
-------------------------------------------------
struct FloatingPointControl
{
void foo() pure
{
auto impl = function bool() {
setControlState(0);
setControlState(0);
return 0;
};
}
private:
static void setControlState(uint newState)
{
}
}
-------------------------------------------------
dmd -c test.d
test.d(7): Error: pure function test.FloatingPointControl.foo cannot call impure function test.FloatingPointControl.setControlState
Comment one of the setControlState calls and the test case compiles.
Comment #1 by johannespfau — 2018-09-08T12:45:29Z
Same problem with static nested functions:
-------------------------------------------------
struct FloatingPointControl
{
void foo() pure
{
static bool nested() {
setControlState(0);
setControlState(0);
return 0;
}
}
private:
static void setControlState(uint newState)
{
}
}
-------------------------------------------------
Comment #2 by razvan.nitu1305 — 2023-04-28T11:14:56Z
The code compiles with the latest git master, which is correct: you can define a non pure function in a pure function as long as you don't call it.