Skip to content

Commit 658dab3

Browse files
committed
Fix 1
1 parent 0b6b8d7 commit 658dab3

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

compiler/src/dmd/funcsem.d

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,6 @@ void funcDeclarationSemantic(Scope* sc, FuncDeclaration funcdecl)
328328
* static auto boo() {} // typed as impure
329329
* // Even though, boo cannot call any impure functions.
330330
* // See also Expression::checkPurity().
331-
* }
332331
*/
333332
if (tf.purity == PURE.impure && (funcdecl.isNested() || funcdecl.isThis()))
334333
{
@@ -1720,19 +1719,19 @@ FuncDeclaration resolveFuncCall(Loc loc, Scope* sc, Dsymbol s,
17201719
{
17211720
// Special case for immutable constructor with mutable arguments
17221721
// This directly addresses issue #20075
1723-
.error(loc, "none of the overloads of `%s` are callable using argument types `(%s)`",
1722+
.error(loc, "none of the overloads of `%s` can construct an immutable object with argument types `(%s)`",
17241723
fd.toChars(), buf.peekChars());
17251724

17261725
// The compiler will print the available candidates later
17271726
}
17281727
else
17291728
{
1730-
.error(loc, "none of the overloads of `%s` are callable using argument types `(%s)`",
1731-
fd.toChars(), buf.peekChars());
1729+
.error(loc, "none of the overloads of `%s` can construct a %s object with argument types `(%s)`",
1730+
fd.toChars(), thisBuf.peekChars(), buf.peekChars());
17321731
}
17331732
}
17341733
else
1735-
.error(loc, "none of the overloads of `%s` are callable using a %sobject with argument types `(%s)`",
1734+
.error(loc, "none of the overloads of `%s` are callable using a %s object with argument types `(%s)`",
17361735
fd.toChars(), thisBuf.peekChars(), buf.peekChars());
17371736

17381737
if (!global.gag || global.params.v.showGaggedErrors)
@@ -1762,10 +1761,10 @@ FuncDeclaration resolveFuncCall(Loc loc, Scope* sc, Dsymbol s,
17621761
return null;
17631762

17641763
if (fd.isCtorDeclaration())
1765-
.error(loc, "%s%s `%s` cannot construct a %sobject",
1764+
.error(loc, "%s%s `%s` cannot construct a %s object",
17661765
funcBuf.peekChars(), fd.kind(), fd.toPrettyChars(), thisBuf.peekChars());
17671766
else
1768-
.error(loc, "%smethod `%s` is not callable using a %sobject",
1767+
.error(loc, "%smethod `%s` is not callable using a %s object",
17691768
funcBuf.peekChars(), fd.toPrettyChars(), thisBuf.peekChars());
17701769

17711770
if (mismatches.isNotShared)
@@ -2246,7 +2245,7 @@ FuncDeclaration overloadModMatch(FuncDeclaration thisfd, Loc loc, Type tthis, re
22462245
OutBuffer thisBuf, funcBuf;
22472246
MODMatchToBuffer(&thisBuf, tthis.mod, tf.mod);
22482247
MODMatchToBuffer(&funcBuf, tf.mod, tthis.mod);
2249-
.error(loc, "%smethod %s is not callable using a %sobject", thisfd.kind, thisfd.toPrettyChars,
2248+
.error(loc, "%smethod %s is not callable using a %s object", thisfd.kind, thisfd.toPrettyChars,
22502249
funcBuf.peekChars(), thisfd.toPrettyChars(), thisBuf.peekChars());
22512250
}
22522251
}
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
/*
22
TEST_OUTPUT:
33
---
4-
fail_compilation/fix20075.d(13): Error: none of the overloads of `this` are callable using argument types `(int*)`
5-
fail_compilation/fix20075.d(18): Candidate is: `fix20075.Foo.this(immutable(int*) a) immutable`
6-
fail_compilation/fix20075.d(13): Note: Constructor expects immutable argument(s), but mutable was supplied
4+
fail_compilation/fix20075.d(15): Error: none of the overloads of `this` can construct a `immutable` object with argument types `(int*)`
5+
fail_compilation/fix20075.d(11): Candidate is: `fix20075.Foo.this(immutable(int*) a) immutable`
76
---
87
*/
98

109
// Test for issue #20075 - "none of the overloads of __ctor are callable using a immutable object" error message is backwards
1110

11+
struct Foo {
12+
@disable this();
13+
immutable this(immutable int* a) {}
14+
}
15+
1216
immutable(Foo) getFoo(int* a) {
1317
return immutable Foo(a);
1418
}
1519

16-
struct Foo {
17-
@disable this();
18-
immutable this(immutable int* a) {}
20+
void main() {
21+
int x;
22+
auto foo = getFoo(&x);
1923
}

0 commit comments

Comments
 (0)