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.
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.