Bug 10736 – Regression (2.064 git-head): Instantiation failure triggered by module import and module order
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-07-31T13:16:00Z
Last change time
2013-08-06T23:22:42Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
andrej.mitrovich
Comments
Comment #0 by andrej.mitrovich — 2013-07-31T13:16:15Z
Three files:
foo\all.d:
-----
module foo.all;
import foo.array;
import foo.range;
-----
foo\array.d:
-----
module foo.array;
import std.range;
-----
foo\range.d:
-----
module foo.range;
import std.range;
void main()
{
int[] arr = [0, 1, 2, 3];
auto x = chunks(arr, 4); // error
}
-----
Compile (in this exact order):
$ dmd foo\all.d foo\array.d foo\range.d
> C:\dmd-git\dmd2\windows\bin\..\..\src\phobos\std\range.d(6543): Error: template std.range.chunks does not match any function template declaration.
If you remove the import to `std.range` inside of `foo.array`, it will compile.
$ dmd foo\all.d foo\array.d foo\range.d
>
If you instead change the compilation order so 'foo\range.d' is compiled first, then it will also compile:
$ foo\range.d dmd foo\all.d foo\array.d
>
Comment #2 by github-bugzilla — 2013-08-06T22:03:37Z
Commits pushed to master at https://github.com/D-Programming-Language/dmdhttps://github.com/D-Programming-Language/dmd/commit/f58e9b20ffb865b4256b4fed917d3e5afc1e914b
fix Issue 10736 - Regression (2.064 git-head): Instantiation failure triggered by module import and module order
In the reduced test case, `test10736b` instantiates `chunks` template
function, then it instantiates `Chunks!(int[])`. The instance object will
be inserted to `test10736a` member because it is the first module that
importing `test10736c`. But in this time, `test10736a` module's semantic3
is already done, then `Chunks!(int[])` would immediately invoke its
semantic3, then `Chunks!(int[]).opSlice` refers *not yet instantiation
finished* `chunks` template.
To avoid the forward reference problem, we should defer semantic3 of
template instances which inserted to module scope.
https://github.com/D-Programming-Language/dmd/commit/314a1cca9ff56775b9e2a9cf81564135be0726b1
Merge pull request #2442 from 9rnsr/fix10736
[REG2.064a] fix Issue 10736 - Regression (2.064 git-head): Instantiation failure triggered by module import and module order