Closed nathanielknight closed 1 year ago
Hi @nathanielknight - thanks for posting this issue report.
I've been able to reproduce the issue with main
. Looking at the compilation output with --devel
, I can see that the compiler is having a problem in trying to default-initialize Beacon
.
But, it's not obvious to me why Beacon
should need to be default-initialized at all for this code. And if it does, and the proc init()
is missing, you should get a better error. So there is more to fix here.
Anyway, here is a version of your reproducer with the workaround:
use IO, FileSystem, FormattedIO, List;
config const inf = "input.txt";
type Point = (int, int);
record Beacon {
const location: Point, beacon: Point;
proc init() { } // Added Workaround Here
proc init(location: Point, beacon: Point) {
this.location = location;
this.beacon = beacon;
}
proc beaconDistance(): int {
return abs(this.location[0] - this.beacon[0]) + abs(this.location[1] - this.location[0]);
}
}
iter loadInput() {
var a, b, c, d: int;
const f = open(inf, iomode.r).reader();
while f.readf("Sensor at x=%i, y=%i: closest beacon is at x=%i, y=%i\n", a, b, c, d) {
yield new Beacon((a, b), (c, d));
}
}
proc blockedCells(ycoord: int, beacons: [?]Beacon): int {
return 0;
}
proc main() {
const beacons: list(Beacon) = loadInput();
writeln(beacons);
}
Inside the compiler, it looks like what is happening here is:
ResolutionCandidate::checkGenericFormals
is considering a candidate where the actual is an iterator record and the formal is owned
getInstantiationType
which calls getCopyTypeDuringResolution
which calls getInitCopyDuringResolution
.getInitCopyDuringResolution
ends up trying to resolve dsiBuildArrayWith
on a DefaultRectangular array.dsiBuildArrayWith
passes initElts=true
but I think that's wrong.Ideally, we could discard this candidate earlier. But, in any case, I think the main problem here is in the module code.
The comment here is wrong. And there's no one to git blame
but myself!
I confess, a lot of that went over my head 😅, but thanks for the swift response, and the workaround :+1:.
@nathanielknight : Thanks for reporting the bug. If it helps, I interpret Michael's diagnosis as being more directed at the compiler team than you. :)
Summary of Problem
Compilation of the following program (which was written while attempting to solve an Advent of Code challenge) failed with this error message:
Steps to Reproduce
Source Code:
Compile command:
Configuration Information