-6e44734ccbeb78252a52e129a67fefb313679948
+792f0fdf249b21531dc91690024827f4f9ecbb97
The first line of this file holds the git revision number of the last
merge done from the dlang/dmd repository.
baseClass = tc->sym;
b->sym = baseClass;
- if (tc->sym->_scope && tc->sym->baseok < BASEOKdone)
+ if (tc->sym->baseok < BASEOKdone)
resolveBase(this, sc, scx, tc->sym); // Try to resolve forward reference
if (tc->sym->baseok < BASEOKdone)
{
b->sym = tc->sym;
- if (tc->sym->_scope && tc->sym->baseok < BASEOKdone)
+ if (tc->sym->baseok < BASEOKdone)
resolveBase(this, sc, scx, tc->sym); // Try to resolve forward reference
if (tc->sym->baseok < BASEOKdone)
{
{
/* cd->baseClass might not be set if cd is forward referenced.
*/
- if (!cd->baseClass && cd->_scope && !cd->isInterfaceDeclaration())
+ if (!cd->baseClass && cd->semanticRun < PASSsemanticdone && !cd->isInterfaceDeclaration())
{
cd->semantic(NULL);
- if (!cd->baseClass && cd->_scope)
+ if (!cd->baseClass && cd->semanticRun < PASSsemanticdone)
cd->error("base class is forward referenced by %s", toChars());
}
b->sym = tc->sym;
- if (tc->sym->_scope && tc->sym->baseok < BASEOKdone)
+ if (tc->sym->baseok < BASEOKdone)
resolveBase(this, sc, scx, tc->sym); // Try to resolve forward reference
if (tc->sym->baseok < BASEOKdone)
{
_scope = NULL;
}
+ if (!sc)
+ return;
+
+ semanticRun = PASSsemantic;
+
/* Pick up storage classes from context, but except synchronized,
* override, abstract, and final.
*/
else if (isAliasThisTuple(e))
{
VarDeclaration *v = copyToTemp(0, "__tup", e);
+ v->semantic(sc);
VarExp *ve = new VarExp(loc, v);
ve->type = e->type;
if (!e)
{
error("is not a static and cannot have static initializer");
- return;
+ e = new ErrorExp();
}
}
ei = new ExpInitializer(_init->loc, e);
_scope = NULL;
}
+ if (!sc)
+ return;
+
parent = sc->parent;
type = type->semantic(loc, sc);
void Import::semantic(Scope *sc)
{
//printf("Import::semantic('%s') %s\n", toPrettyChars(), id->toChars());
+ if (semanticRun > PASSinit)
+ return;
if (_scope)
{
sc = _scope;
_scope = NULL;
}
+ if (!sc)
+ return;
+
+ semanticRun = PASSsemantic;
// Load if not already done so
if (!mod)
sc = sc->pop();
}
+ semanticRun = PASSsemanticdone;
+
// object self-imports itself, so skip that (Bugzilla 7547)
// don't list pseudo modules __entrypoint.d, __main.d (Bugzilla 11117, 11164)
if (global.params.moduleDeps != NULL &&
if (v->ident == Id::ctfe)
return new IntegerExp(loc, 1, Type::tbool);
- if (!v->originalType && v->_scope) // semantic() not yet run
+ if (!v->originalType && v->semanticRun < PASSsemanticdone) // semantic() not yet run
{
- v->semantic (v->_scope);
+ v->semantic(NULL);
if (v->type->ty == Terror)
return CTFEExp::cantexp;
}
// Bugzilla 15149, if the typeid operand type comes from a
// result of auto function, it may be yet speculative.
- unSpeculative(sc, sd);
+ // unSpeculative(sc, sd);
}
/* Step 2: If the TypeInfo generation requires sd.semantic3, run it later.
if (sd)
sd->semanticTypeInfoMembers();
+ semanticRun = PASSsemantic3done;
}
/***************************************
AggregateDeclaration *ad = ((SV *)param)->agg;
- if (v->_scope)
+ if (v->semanticRun < PASSsemanticdone)
v->semantic(NULL);
// Note: Aggregate fields or size could have determined during v->semantic.
if (ad->sizeok != SIZEOKnone)
/* BUG: should check:
* o no virtual functions or non-static data members of classes
*/
+ semanticRun = PASSsemanticdone;
}
const char *TemplateDeclaration::kind() const
if (tiargs && tiargs->dim > 0)
return 0;
- if (fd->semanticRun == PASSinit && fd->_scope)
+ // constructors need a valid scope in order to detect semantic errors
+ if (!fd->isCtorDeclaration() &&
+ fd->semanticRun < PASSsemanticdone)
{
Ungag ungag = fd->ungagSpeculative();
- fd->semantic(fd->_scope);
+ fd->semantic(NULL);
}
- if (fd->semanticRun == PASSinit)
+ if (fd->semanticRun < PASSsemanticdone)
{
::error(loc, "forward reference to template %s", fd->toChars());
return 1;
tf = (TypeFunction *)ce->f->type;
/* If a forward reference to ce->f, try to resolve it
*/
- if (!tf->deco && ce->f->_scope)
+ if (!tf->deco && ce->f->semanticRun < PASSsemanticdone)
{
- ce->f->semantic(ce->f->_scope);
+ ce->f->semantic(NULL);
tf = (TypeFunction *)ce->f->type;
}
}
Type *t0 = NULL;
Expression *e0 = NULL; // dead-store to prevent spurious warning
size_t j0 = ~0; // dead-store to prevent spurious warning
+ bool foundType = false;
+
for (size_t i = 0; i < exps->dim; i++)
{
Expression *e = (*exps)[i];
}
if (e->op == TOKtype)
{
+ foundType = true; // do not break immediately, there might be more errors
e->checkValue(); // report an error "type T has no value"
t0 = Type::terror;
continue;
e = doCopyOrMove(sc, e);
- if (t0 && !t0->equals(e->type))
+ if (!foundType && t0 && !t0->equals(e->type))
{
/* This applies ?: to merge the types. It's backwards;
* ?: should call this function to merge types.
// Create the magic __ctfe bool variable
VarDeclaration *vd = new VarDeclaration(exp->loc, Type::tbool, Id::ctfe, NULL);
vd->storage_class |= STCtemp;
+ vd->semanticRun = PASSsemanticdone;
Expression *e = new VarExp(exp->loc, vd);
e = semantic(e, sc);
result = e;
void visit(VarExp *e)
{
- if (FuncDeclaration *fd = e->var->isFuncDeclaration())
+ VarDeclaration *vd = e->var->isVarDeclaration();
+ FuncDeclaration *fd = e->var->isFuncDeclaration();
+
+ if (fd)
{
//printf("L%d fd = %s\n", __LINE__, f->toChars());
if (!fd->functionSemantic())
e->type = e->var->type;
if (e->type && !e->type->deco)
+ {
+ Declaration *decl = e->var->isDeclaration();
+ if (decl)
+ decl->inuse++;
e->type = e->type->semantic(e->loc, sc);
+ if (decl)
+ decl->inuse--;
+ }
/* Fix for 1161 doesn't work because it causes protection
* problems when instantiating imported templates passing private
*/
//checkAccess(e->loc, sc, NULL, e->var);
- if (VarDeclaration *vd = e->var->isVarDeclaration())
+ if (vd)
{
if (vd->checkNestedReference(sc, e->loc))
return setError();
// the purity violation error is redundant.
//checkPurity(sc, vd);
}
- else if (FuncDeclaration *fd = e->var->isFuncDeclaration())
+ else if (fd)
{
// TODO: If fd isn't yet resolved its overload, the checkNestedReference
// call would cause incorrect validation.
ClassDeclaration *cd = ((TypeClass *)e->targ)->sym;
Parameters *args = new Parameters;
args->reserve(cd->baseclasses->dim);
- if (cd->_scope && !cd->symtab)
- cd->semantic(cd->_scope);
+ if (cd->semanticRun < PASSsemanticdone)
+ cd->semantic(NULL);
for (size_t i = 0; i < cd->baseclasses->dim; i++)
{
BaseClass *b = (*cd->baseclasses)[i];
_scope = NULL;
}
+ if (!sc || errors)
+ return;
+
parent = sc->parent;
Dsymbol *parent = toParent();
case -2:
// can't determine because of forward references
+ errors = true;
return;
default:
case -2:
// can't determine because of forward references
+ errors = true;
return;
default:
/* AA's need typeid(index).equals() and getHash(). Issue error if not correctly set up.
*/
StructDeclaration *sd = ((TypeStruct *)tbase)->sym;
- if (sd->_scope)
+ if (sd->semanticRun < PASSsemanticdone)
sd->semantic(NULL);
// duplicate a part of StructDeclaration::semanticTypeInfoMembers
else if (tbase->ty == Tclass && !((TypeClass *)tbase)->sym->isInterfaceDeclaration())
{
ClassDeclaration *cd = ((TypeClass *)tbase)->sym;
- if (cd->_scope)
+ if (cd->semanticRun < PASSsemanticdone)
cd->semantic(NULL);
if (!ClassDeclaration::object)
// If t1n is forward referenced:
ClassDeclaration *cd = ((TypeClass *)t1n)->sym;
- if (cd->_scope)
+ if (cd->semanticRun < PASSsemanticdone && !cd->isBaseInfoComplete())
cd->semantic(NULL);
if (!cd->isBaseInfoComplete())
{
bool errors = false;
+ if (inuse > 500)
+ {
+ inuse = 0;
+ ::error(loc, "recursive type");
+ return Type::terror;
+ }
+
/* Copy in order to not mess up original.
* This can produce redundant copies if inferring return type,
* as semantic() will get called again on this.
for (size_t i = 0; i < dim; i++)
{
Parameter *fparam = Parameter::getNth(tf->parameters, i);
- tf->inuse++;
+ inuse++;
fparam->type = fparam->type->semantic(loc, argsc);
- if (tf->inuse == 1) tf->inuse--;
+ inuse--;
if (fparam->type->ty == Terror)
{
}
tf->iswild = wildparams;
- if (tf->inuse)
- {
- error(loc, "recursive type");
- tf->inuse = 0;
- errors = true;
- }
-
if (tf->isproperty && (tf->varargs || Parameter::dim(tf->parameters) > 2))
{
error(loc, "properties can only have zero, one, or two parameter");
if (ident == Id::_mangleof)
return getProperty(e->loc, ident, flag & 1);
- if (sym->_scope)
- sym->semantic(sym->_scope);
+ if (sym->semanticRun < PASSsemanticdone)
+ sym->semantic(NULL);
if (!sym->members)
{
if (sym->isSpecial())
return e;
}
}
- if (d->semanticRun == PASSinit && d->_scope)
- d->semantic(d->_scope);
+ if (d->semanticRun == PASSinit)
+ d->semantic(NULL);
checkAccess(e->loc, sc, e, d);
VarExp *ve = new VarExp(e->loc, d);
if (d->isVarDeclaration() && d->needThis())
if (ident == Id::outer && sym->vthis)
{
- if (sym->vthis->_scope)
+ if (sym->vthis->semanticRun == PASSinit)
sym->vthis->semantic(NULL);
if (ClassDeclaration *cdp = sym->toParent2()->isClassDeclaration())
}
}
//printf("e = %s, d = %s\n", e->toChars(), d->toChars());
- if (d->semanticRun == PASSinit && d->_scope)
- d->semantic(d->_scope);
+ if (d->semanticRun == PASSinit)
+ d->semantic(NULL);
checkAccess(e->loc, sc, e, d);
VarExp *ve = new VarExp(e->loc, d);
if (d->isVarDeclaration() && d->needThis())
if (cdto)
{
//printf("TypeClass::implicitConvTo(to = '%s') %s, isbase = %d %d\n", to->toChars(), toChars(), cdto->isBaseInfoComplete(), sym->isBaseInfoComplete());
- if (cdto->_scope && !cdto->isBaseInfoComplete())
+ if (cdto->semanticRun < PASSsemanticdone && !cdto->isBaseInfoComplete())
cdto->semantic(NULL);
- if (sym->_scope && !sym->isBaseInfoComplete())
+ if (sym->semanticRun < PASSsemanticdone && !sym->isBaseInfoComplete())
sym->semantic(NULL);
if (cdto->isBaseOf(sym, NULL) && MODimplicitConv(mod, to->mod))
{
Expression *e = NULL;
if (!v)
return e;
- if (!v->originalType && v->_scope) // semantic() not yet run
- v->semantic (v->_scope);
+ if (!v->originalType && v->semanticRun < PASSsemanticdone) // semantic() not yet run
+ v->semantic(NULL);
if (v->isConst() || v->isImmutable() || v->storage_class & STCmanifest)
{
return new OnScopeStatement(loc, tok, statement->syntaxCopy());
}
-Statement *OnScopeStatement::scopeCode(Scope *, Statement **sentry, Statement **sexception, Statement **sfinally)
+Statement *OnScopeStatement::scopeCode(Scope *sc, Statement **sentry, Statement **sexception, Statement **sfinally)
{
//printf("OnScopeStatement::scopeCode()\n");
//print();
* sfinally: if (!x) statement;
*/
VarDeclaration *v = copyToTemp(0, "__os", new IntegerExp(Loc(), 0, Type::tbool));
+ v->semantic(sc);
*sentry = new ExpStatement(loc, v);
Expression *e = new IntegerExp(Loc(), 1, Type::tbool);
else
{
r = copyToTemp(0, "__r", fs->aggr);
+ r->semantic(sc);
init = new ExpStatement(loc, r);
if (vinit)
init = new CompoundStatement(loc, new ExpStatement(loc, vinit), init);
else
{
VarDeclaration *vd = copyToTemp(STCref, "__front", einit);
+ vd->semantic(sc);
makeargs = new ExpStatement(loc, vd);
Type *tfront = NULL;
* try { body } finally { _d_monitorexit(tmp); }
*/
VarDeclaration *tmp = copyToTemp(0, "__sync", ss->exp);
+ tmp->semantic(sc);
Statements *cs = new Statements();
cs->push(new ExpStatement(ss->loc, tmp));
* }
*/
VarDeclaration *tmp = copyToTemp(0, "__withtmp", ws->exp);
+ tmp->semantic(sc);
ExpStatement *es = new ExpStatement(ws->loc, tmp);
ws->exp = new VarExp(ws->loc, tmp);
Statement *ss = new ScopeStatement(ws->loc, new CompoundStatement(ws->loc, es, ws), ws->endloc);
e->error("argument %s has no protection", o->toChars());
return new ErrorExp();
}
- if (s->_scope)
- s->semantic(s->_scope);
+ if (s->semanticRun == PASSinit)
+ s->semantic(NULL);
const char *protName = protectionToChars(s->prot().kind); // TODO: How about package(names)
assert(protName);
ClassDeclaration *cd = sds->isClassDeclaration();
if (cd && e->ident == Id::allMembers)
{
- if (cd->_scope)
+ if (cd->semanticRun < PASSsemanticdone)
cd->semantic(NULL); // Bugzilla 13668: Try to resolve forward reference
struct PushBaseMembers
--- /dev/null
+module test16214b;
+import test16214a;
+
+struct Appender() { int[] arr; }
+struct Tuple() { alias A = Appender!(); }
+
+class EventLoop
+{
+ auto f() { auto x = [Tuple!().init]; }
+}
--- /dev/null
+// EXTRA_SOURCES: imports/test16214b.d
+// REQUIRED_ARGS: -Icompilable/imports
+
+module test16214a;
+import test16214b;
+
+class LibasyncEventLoop : EventLoop {}
--- /dev/null
+/* TEST_OUTPUT:
+---
+fail_compilation/b15875.d(9): Error: circular reference to variable `a`
+fail_compilation/b15875.d(10): Error: circular reference to `b15875.f`
+---
+*/
+// https://issues.dlang.org/show_bug.cgi?id=15875
+// https://issues.dlang.org/show_bug.cgi?id=17290
+d o(int[a]a)(){}
+f.T f(){}
--- /dev/null
+/*
+TEST_OUTPUT:
+---
+fail_compilation/b17285.d(14): Error: type `ONE` has no value
+fail_compilation/b17285.d(14): Error: type `TWO` has no value
+fail_compilation/b17285.d(14): Error: cannot implicitly convert expression `ONE` of type `b17285.ONE` to `int`
+---
+*/
+
+class ONE {}
+enum TWO;
+
+void foo() {
+ foreach(key; [ONE, TWO, 1]) {}
+}
--- /dev/null
+// REQUIRED_ARGS: -de
+/* TEST_OUTPUT:
+---
+fail_compilation/b19691.d(13): Error: forward reference to template `this`
+fail_compilation/b19691.d(19): Deprecation: constructor `b19691.S2.this` all parameters have default arguments, but structs cannot have default constructors.
+---
+*/
+// https://issues.dlang.org/show_bug.cgi?id=19691
+module b19691;
+
+struct S1 {
+ this(T...)(T) {
+ S2("");
+ }
+}
+
+struct S2 {
+ this(string) {}
+ this(S1 s = null) {}
+}
--- /dev/null
+// REQUIRED_ARGS: -de
+/* TEST_OUTPUT:
+---
+fail_compilation/b19691e.d(17): Error: forward reference to template `this`
+fail_compilation/b19691e.d(17): Error: constructor `b19691e.S2.this(S1 s = "")` is not callable using argument types `(string)`
+fail_compilation/b19691e.d(17): Error: forward reference to template `this`
+fail_compilation/b19691e.d(23): Deprecation: constructor `b19691e.S2.this` all parameters have default arguments, but structs cannot have default constructors.
+---
+*/
+// https://issues.dlang.org/show_bug.cgi?id=19691
+module b19691e;
+
+struct S1
+{
+ this(T)(T)
+ {
+ S2("");
+ }
+}
+
+struct S2
+{
+ this(S1 s = ""){}
+}
--- /dev/null
+/*
+TEST_OUTPUT:
+---
+fail_compilation/b19717.d(16): Error: undefined identifier `Foo`, did you mean function `foo`?
+fail_compilation/b19717.d(13): Error: forward reference to template `foo`
+fail_compilation/b19717.d(13): Error: forward reference to inferred return type of function call `foo()`
+---
+*/
+
+enum bar = __traits(getMember, mixin(__MODULE__), "foo");
+
+auto foo() {
+ return foo();
+}
+
+void foo(Foo) {}
--- /dev/null
+// REQUIRED_ARGS: -de
+/* TEST_OUTPUT:
+---
+fail_compilation/b19717a.d(14): Error: forward reference to template `a`
+fail_compilation/b19717a.d(14): Error: forward reference to template `a`
+fail_compilation/b19717a.d(14): Error: none of the overloads of `a` are callable using argument types `()`, candidates are:
+fail_compilation/b19717a.d(13): `b19717a.a(int b)`
+fail_compilation/b19717a.d(14): `b19717a.a(int b = a)`
+---
+*/
+module b19717a;
+
+auto a(int b) {}
+auto a(int b = a) {}