Skip to content

Commit

Permalink
Merge pull request #3274 from 9rnsr/2.065
Browse files Browse the repository at this point in the history
Pick up changes from master to 2.065 branch
  • Loading branch information
9rnsr committed Feb 16, 2014
2 parents b70737a + 79ae211 commit a1ef105
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/struct.c
Expand Up @@ -827,6 +827,29 @@ void StructDeclaration::semantic(Scope *sc)
aggNew = (NewDeclaration *)search(Loc(), Id::classNew);
aggDelete = (DeleteDeclaration *)search(Loc(), Id::classDelete);

if (ctor)
{
Dsymbol *scall = search(Loc(), Id::call);
if (scall)
{
unsigned errors = global.startGagging();
unsigned oldspec = global.speculativeGag;
global.speculativeGag = global.gag;
sc = sc->push();
sc->speculative = true;
FuncDeclaration *fcall = resolveFuncCall(loc, sc, scall, NULL, NULL, NULL, 1);
sc = sc->pop();
global.speculativeGag = oldspec;
global.endGagging(errors);

if (fcall && fcall->isStatic())
{
error(fcall->loc, "static opCall is hidden by constructors and can never be called");
errorSupplemental(fcall->loc, "Please use a factory method instead, or replace all constructors with static opCall.");
}
}
}

TypeTuple *tup = type->toArgTypes();
size_t dim = tup->arguments->dim;
if (dim >= 1)
Expand Down
21 changes: 21 additions & 0 deletions test/fail_compilation/diag12124.d
@@ -0,0 +1,21 @@
/*
TEST_OUTPUT:
---
fail_compilation/diag12124.d(14): Error: struct diag12124.S1 static opCall is hidden by constructors and can never be called
fail_compilation/diag12124.d(14): Please use a factory method instead, or replace all constructors with static opCall.
fail_compilation/diag12124.d(20): Error: struct diag12124.S2 static opCall is hidden by constructors and can never be called
fail_compilation/diag12124.d(20): Please use a factory method instead, or replace all constructors with static opCall.
---
*/

struct S1
{
this(int) {}
static S1 opCall() { assert(0); }
}

struct S2
{
this(int) {}
static S2 opCall()() { assert(0); }
}
10 changes: 10 additions & 0 deletions test/runnable/opover3.d
Expand Up @@ -159,6 +159,16 @@ void test12070()
assert(result == "c1x0x1x2");
}

/**************************************/
// 12124

struct S12124
{
this(int) {}
S12124 opCall()() { static assert(0); }
// speculative opCall instantiation for diagnostic message should not cause false errors
}

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

void main()
Expand Down

0 comments on commit a1ef105

Please sign in to comment.