Bug 14965 – [REG2.031] Forward reference to inferred return type of function call when using auto return type

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-08-26T19:20:00Z
Last change time
2016-03-07T20:06:49Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
chalucha

Comments

Comment #0 by chalucha — 2015-08-26T19:20:08Z
import std.stdio; import std.range : chain; auto test(string a) { return test(a, "b"); } auto test(string a, string b) { return chain(a, b); } void main() { writeln(test(a)); } Ends with: Error: forward reference to inferred return type of function call 'test' I know this exact sample is solvable by default parameter but there are cases where it is not possible. Workaround is discussed here: http://forum.dlang.org/post/[email protected]
Comment #1 by timon.gehr — 2015-08-26T19:38:20Z
Minimal example: auto foo(){ return foo(0); } int foo(int x){ return x; } (Also, the original post has a typo, I suspect main should do writeln(test("a")).)
Comment #2 by dlang-bugzilla — 2015-09-01T10:54:29Z
(In reply to timon.gehr from comment #1) > auto foo(){ return foo(0); } > int foo(int x){ return x; } This appears to be a regression (introduced in DMD 2.031).
Comment #3 by k.hara.pg — 2015-10-19T14:54:24Z
Comment #4 by trikko — 2016-02-02T11:54:05Z
Recursive example: auto guessreturn(uint i) { if (i == 0) return 0; else return guessreturn(i-1); }
Comment #5 by github-bugzilla — 2016-03-07T20:06:49Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/4b6779d2ff0b95866205189cb55e5aef00c13c7e fix Issue 14965 - Forward reference to inferred return type of function call when using auto return type If a function symbol is used, its overload resolution should be deferred until: ```d func(...) // CallExp.semantic func.mangleof // DotIdExp.semanticY typeof(func) // TypeTypeof.resolve typeof(&func) // TypeTypeof.resolve auto v = &func; // ExpInitializer.inferType &func; // ExpStatement.semantic return &func; // ReturnStatement ``` When the semantic analysis reaches to them, the function forward reference can beome actual error. Other use of 'func' should be treated as a property-like function call (done in `resolveProperties`) and finally handled in `CallExp`. https://github.com/D-Programming-Language/dmd/commit/624ad66c0bbfdfad8c5c1fc95339f77ac3659694 Merge pull request #5202 from 9rnsr/fix14965 [REG2.031] Issue 14965 - Forward reference to inferred return type of function call when using auto return type