Bug 190 – Cannot forward reference typedef/alias in default value for function parameter

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P3
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2006-06-11T06:46:00Z
Last change time
2014-02-15T13:22:10Z
Keywords
rejects-valid
Assigned to
bugzilla
Creator
matti.niemenmaa+dbugzilla
Blocks
340, 3979

Attachments

IDFilenameSummaryContent-TypeSize
858bug190.diffUpdated patchtext/plain1853

Comments

Comment #0 by matti.niemenmaa+dbugzilla — 2006-06-11T06:46:37Z
Possibly related to Bug 184. -- typedef int avocado; void eat(avocado x = .x); avocado x; -- The above code fails to compile with the error "cannot implicitly convert expression (x) of type avocado to avocado". Changing the typedef to an alias causes "cannot implicitly convert expression (x) of type avocado to int" instead. Placing the declaration of "x" before the declaration of "eat" makes it compile just fine.
Comment #1 by bugzilla — 2008-06-23T17:27:11Z
*** Bug 217 has been marked as a duplicate of this bug. ***
Comment #2 by bugzilla — 2008-06-23T17:27:42Z
Another test case: ---- extern(C) void bar(foo b); alias typeof(int.sizeof) foo; void main() { bar(1); } ----
Comment #3 by r.sagitario — 2010-07-20T14:07:12Z
The problem of the original test case is the default initializer. It is evaluated when the type of the function is inferred, but the referenced variable has not yet been semantically analyzed. Here's a patch: Index: expression.c =================================================================== --- expression.c (revision 576) +++ expression.c (working copy) @@ -4350,6 +4350,8 @@ } #endif } + if(type && !type->deco) + type = type->semantic(loc, sc); /* Fix for 1161 doesn't work because it causes protection * problems when instantiating imported templates passing private @@ -6046,7 +6048,8 @@ e->type = v->type; } } - return e->deref(); + e = e->deref(); + return e->semantic(sc); } FuncDeclaration *f = s->isFuncDeclaration(); The test case in comment 2 is something different and compiles with DMD 2.047.
Comment #4 by bugzilla — 2010-08-27T16:03:09Z
Comment #5 by braddr — 2010-08-30T00:41:06Z
Reopening due to a regression it causes. See bug 4753 for the details.
Comment #6 by bugzilla — 2010-08-30T14:01:53Z
Comment #7 by braddr — 2010-08-31T23:00:44Z
A recursion limiting patch has been added to bug 4753.
Comment #8 by braddr — 2011-01-02T19:43:03Z
Created attachment 858 Updated patch Incorporates the fixes from bug 4753 for the regression from the previous version of the patch. Tested against the code in bugs 190, 4573, and all the unit tests for dmd, druntime, and phobos.
Comment #9 by bugzilla — 2011-01-03T00:33:59Z