Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
some return types disqualify comptime fn call caching
closes #828
- Loading branch information
Showing
6 changed files
with
86 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const CountBy = struct { | ||
a: usize, | ||
|
||
const One = CountBy { | ||
.a = 1, | ||
}; | ||
|
||
pub fn counter(self: &const CountBy) Counter { | ||
return Counter { | ||
.i = 0, | ||
}; | ||
} | ||
}; | ||
|
||
const Counter = struct { | ||
i: usize, | ||
|
||
pub fn count(self: &Counter) bool { | ||
self.i += 1; | ||
return self.i <= 10; | ||
} | ||
}; | ||
|
||
fn constCount(comptime cb: &const CountBy, comptime unused: u32) void { | ||
comptime { | ||
var cnt = cb.counter(); | ||
if(cnt.i != 0) @compileError("Counter instance reused!"); | ||
while(cnt.count()){} | ||
} | ||
} | ||
|
||
test "comptime struct return should not return the same instance" { | ||
//the first parameter must be passed by reference to trigger the bug | ||
//a second parameter is required to trigger the bug | ||
const ValA = constCount(&CountBy.One, 12); | ||
const ValB = constCount(&CountBy.One, 15); | ||
} |