Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typeMerge should take modifiers into account when searching for common base class #5450

Merged
merged 1 commit into from Feb 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/dcast.d
Expand Up @@ -2508,7 +2508,7 @@ extern (C++) Type rawTypeMerge(Type t1, Type t2)
*/
extern (C++) bool typeMerge(Scope* sc, TOK op, Type* pt, Expression* pe1, Expression* pe2)
{
//printf("typeMerge() %s op %s\n", (*pe1)->toChars(), (*pe2)->toChars());
//printf("typeMerge() %s op %s\n", pe1.toChars(), pe2.toChars());
MATCH m;
Expression e1 = *pe1;
Expression e2 = *pe2;
Expand Down Expand Up @@ -2804,8 +2804,8 @@ Lagain:
ClassDeclaration cd2 = tc2.sym.baseClass;
if (cd1 && cd2)
{
t1 = cd1.type;
t2 = cd2.type;
t1 = cd1.type.castMod(t1.mod);
t2 = cd2.type.castMod(t2.mod);
}
else if (cd1)
t1 = cd1.type;
Expand Down
43 changes: 43 additions & 0 deletions test/runnable/xtest46.d
Expand Up @@ -7736,6 +7736,48 @@ void test15369()
assert(*p == '\0');
}

void test15638()
{
class A {}
class B : A {}
class C : A {}

B b;
C c;
const(B) cb;
const(C) cc;
immutable(B) ib;
immutable(C) ic;

// Common type for const derived classes
auto constCommon = true ? cb : cc;
static assert(is(typeof(constCommon) == const(A)));

// Common type for immutable derived classes
auto immutableCommon = true ? ib : ic;
static assert(is(typeof(immutableCommon) == immutable(A)));

// Common type for mixed const/immutable derived classes
auto mixed1 = true ? cb : ic;
static assert(is(typeof(mixed1) == const(A)));
auto mixed2 = true ? ib : cc;
static assert(is(typeof(mixed2) == const(A)));

// Common type for mixed mutable/immutable derived classes
auto mixed3 = true ? b : ic;
static assert(is(typeof(mixed3) == const(A)));
auto mixed4 = true ? ib : c;
static assert(is(typeof(mixed4) == const(A)));

// Array literal type deduction
auto arr1 = [ new immutable(B), new C ];
auto arr2 = [ new B, new const(C) ];
auto arr3 = [ new immutable(B), new immutable(C) ];
static assert(is(typeof(arr1) == const(A)[]));
static assert(is(typeof(arr2) == const(A)[]));
static assert(is(typeof(arr3) == immutable(A)[]));
}

/***************************************************/

int main()
Expand Down Expand Up @@ -8051,6 +8093,7 @@ int main()
test14211();
test15141();
test15369();
test15638();

printf("Success\n");
return 0;
Expand Down