Skip to content

Commit ff4148a

Browse files
committed
fix-20075 more clear error msg now
1 parent 6476ceb commit ff4148a

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

compiler/src/dmd/funcsem.d

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,8 +1713,14 @@ FuncDeclaration resolveFuncCall(Loc loc, Scope* sc, Dsymbol s,
17131713
OutBuffer buf;
17141714
buf.argExpTypesToCBuffer(fargs);
17151715
if (fd.isCtorDeclaration())
1716-
.error(loc, "none of the overloads of `%s` can construct a %sobject with argument types `(%s)`",
1717-
fd.toChars(), thisBuf.peekChars(), buf.peekChars());
1716+
{
1717+
if (tthis.mod & MODFlags.immutable_)
1718+
.error(loc, "none of the overloads of `%s` can construct an immutable object with argument types `(%s)`. Expected `immutable(%s)`",
1719+
fd.toChars(), buf.peekChars(), buf.peekChars());
1720+
else
1721+
.error(loc, "none of the overloads of `%s` can construct a %sobject with argument types `(%s)`",
1722+
fd.toChars(), thisBuf.peekChars(), buf.peekChars());
1723+
}
17181724
else
17191725
.error(loc, "none of the overloads of `%s` are callable using a %sobject with argument types `(%s)`",
17201726
fd.toChars(), thisBuf.peekChars(), buf.peekChars());
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
TEST_OUTPUT:
3+
---
4+
fail_compilation/fix20075.d(15): Error: none of the overloads of `this` can construct an immutable object with argument types `(int*)`. Expected `immutable(int*)`
5+
fail_compilation/fix20075.d(11): Candidate is: `fix20075.Foo.this(immutable(int*) a) immutable`
6+
---
7+
*/
8+
9+
struct Foo {
10+
@disable this();
11+
immutable this(immutable int* a) {}
12+
}
13+
14+
immutable(Foo) getFoo(int* a) {
15+
return immutable Foo(a);
16+
}
17+
18+
void main() {
19+
int x;
20+
auto foo = getFoo(&x);
21+
}

0 commit comments

Comments
 (0)