Mercurial > projects > ddmd
diff dmd/StructLiteralExp.d @ 64:4290d870944a
More fixes
author | korDen |
---|---|
date | Mon, 23 Aug 2010 20:29:15 +0400 |
parents | cab4c37afb89 |
children | f708f0452e81 |
line wrap: on
line diff
--- a/dmd/StructLiteralExp.d Mon Aug 23 16:52:24 2010 +0400 +++ b/dmd/StructLiteralExp.d Mon Aug 23 20:29:15 2010 +0400 @@ -1,6 +1,8 @@ module dmd.StructLiteralExp; import dmd.Expression; +import dmd.MOD; +import dmd.TypeStruct; import dmd.expression.Util; import dmd.ErrorExp; import dmd.Dsymbol; @@ -217,12 +219,39 @@ bool canThrow() { - assert(false); + return arrayExpressionCanThrow(elements); } MATCH implicitConvTo(Type t) { - assert(false); +static if (false) { + printf("StructLiteralExp.implicitConvTo(this=%.*s, type=%.*s, t=%.*s)\n", + toChars(), type.toChars(), t.toChars()); +} + MATCH m = Expression.implicitConvTo(t); + if (m != MATCHnomatch) + return m; + if (type.ty == t.ty && type.ty == Tstruct && (cast(TypeStruct)type).sym == (cast(TypeStruct)t).sym) + { + m = MATCHconst; + for (int i = 0; i < elements.dim; i++) + { + Expression e = cast(Expression)elements.data[i]; + Type te = e.type; + if (t.mod == 0) + te = te.mutableOf(); + else + { + assert(t.mod == MODinvariant); + te = te.invariantOf(); + } + MATCH m2 = e.implicitConvTo(te); + //printf("\t%s => %s, match = %d\n", e.toChars(), te.toChars(), m2); + if (m2 < m) + m = m2; + } + } + return m; } int inlineCost(InlineCostState* ics)