-d16195406e1795ee91f2acb8f522fcb4ec698f47
+0450061c8de71328815da9323bd35c92b37d51d2
The first line of this file holds the git revision number of the last
merge done from the dlang/dmd repository.
*/
bool AggregateDeclaration::determineFields()
{
+ if (_scope)
+ dsymbolSemantic(this, NULL);
if (sizeok != SIZEOKnone)
return true;
virtual UnitTestDeclaration *isUnitTestDeclaration() { return NULL; }
virtual NewDeclaration *isNewDeclaration() { return NULL; }
virtual VarDeclaration *isVarDeclaration() { return NULL; }
+ virtual VersionSymbol *isVersionSymbol() { return NULL; }
+ virtual DebugSymbol *isDebugSymbol() { return NULL; }
virtual ClassDeclaration *isClassDeclaration() { return NULL; }
virtual StructDeclaration *isStructDeclaration() { return NULL; }
virtual UnionDeclaration *isUnionDeclaration() { return NULL; }
ti = dsym->_init ? dsym->_init->syntaxCopy() : NULL;
VarDeclaration *v = new VarDeclaration(dsym->loc, arg->type, id, ti);
- v->storage_class |= STCtemp | dsym->storage_class;
+ v->storage_class |= STCtemp | STClocal | dsym->storage_class;
if (arg->storageClass & STCparameter)
v->storage_class |= arg->storageClass;
//printf("declaring field %s of type %s\n", v->toChars(), v->type->toChars());
}
};
+/******************************************************
+ * Do template instance semantic for isAliasSeq templates.
+ * This is a greatly simplified version of TemplateInstance::semantic().
+ */
+static void aliasSeqInstanceSemantic(TemplateInstance *tempinst, Scope *sc, TemplateDeclaration *tempdecl)
+{
+ //printf("[%s] aliasSeqInstanceSemantic('%s')\n", tempinst->loc.toChars(), tempinst->toChars());
+ Scope *paramscope = sc->push();
+ paramscope->stc = 0;
+ paramscope->protection = Prot(Prot::public_);
+
+ TemplateTupleParameter *ttp = (*tempdecl->parameters)[0]->isTemplateTupleParameter();
+ Tuple *va = isTuple(tempinst->tdtypes[0]);
+ Declaration *d = new TupleDeclaration(tempinst->loc, ttp->ident, &va->objects);
+ d->storage_class |= STCtemplateparameter;
+ dsymbolSemantic(d, sc);
+
+ paramscope->pop();
+
+ tempinst->aliasdecl = d;
+
+ tempinst->semanticRun = PASSsemanticdone;
+}
+
+/******************************************************
+ * Do template instance semantic for isAlias templates.
+ * This is a greatly simplified version of TemplateInstance::semantic().
+ */
+static void aliasInstanceSemantic(TemplateInstance *tempinst, Scope *sc, TemplateDeclaration *tempdecl)
+{
+ //printf("[%s] aliasInstanceSemantic('%s')\n", tempinst->loc.toChars(), tempinst->toChars());
+ Scope *paramscope = sc->push();
+ paramscope->stc = 0;
+ paramscope->protection = Prot(Prot::public_);
+
+ TemplateTypeParameter *ttp = (*tempdecl->parameters)[0]->isTemplateTypeParameter();
+ Type *ta = isType(tempinst->tdtypes[0]);
+ Declaration *d = new AliasDeclaration(tempinst->loc, ttp->ident, ta->addMod(tempdecl->onemember->isAliasDeclaration()->type->mod));
+ d->storage_class |= STCtemplateparameter;
+ dsymbolSemantic(d, sc);
+
+ paramscope->pop();
+
+ tempinst->aliasdecl = d;
+
+ tempinst->semanticRun = PASSsemanticdone;
+}
+
void templateInstanceSemantic(TemplateInstance *tempinst, Scope *sc, Expressions *fargs)
{
//printf("[%s] TemplateInstance::semantic('%s', this=%p, gag = %d, sc = %p)\n", tempinst->loc.toChars(), tempinst->toChars(), tempinst, global.gag, sc);
if (tempinst->errors)
goto Lerror;
+ /* Greatly simplified semantic processing for AliasSeq templates
+ */
+ if (tempdecl->isTrivialAliasSeq)
+ {
+ tempinst->inst = tempinst;
+ return aliasSeqInstanceSemantic(tempinst, sc, tempdecl);
+ }
+ /* Greatly simplified semantic processing for Alias templates
+ */
+ else if (tempdecl->isTrivialAlias)
+ {
+ tempinst->inst = tempinst;
+ return aliasInstanceSemantic(tempinst, sc, tempdecl);
+ }
+
/* See if there is an existing TemplateInstantiation that already
* implements the typeargs. If so, just refer to that one instead.
*/
e->op == TOKtype || e->op == TOKdottype ||
e->op == TOKtemplate || e->op == TOKdottd ||
e->op == TOKfunction || e->op == TOKerror ||
- e->op == TOKthis || e->op == TOKsuper)
+ e->op == TOKthis || e->op == TOKsuper ||
+ e->op == TOKdot)
return false;
if (e->op != TOKdotvar)
this->literal = literal;
this->ismixin = ismixin;
this->isstatic = true;
+ this->isTrivialAliasSeq = false;
+ this->isTrivialAlias = false;
this->previous = NULL;
this->protection = Prot(Prot::undefined);
this->inuse = 0;
// Compute in advance for Ddoc's use
// Bugzilla 11153: ident could be NULL if parsing fails.
- if (members && ident)
+ if (!members || !ident)
+ return;
+
+ Dsymbol *s;
+ if (!Dsymbol::oneMembers(members, &s, ident) || !s)
+ return;
+
+ onemember = s;
+ s->parent = this;
+
+ /* Set isTrivialAliasSeq if this fits the pattern:
+ * template AliasSeq(T...) { alias AliasSeq = T; }
+ * or set isTrivialAlias if this fits the pattern:
+ * template Alias(T) { alias Alias = qualifiers(T); }
+ */
+ if (!(parameters && parameters->length == 1))
+ return;
+
+ AliasDeclaration *ad = s->isAliasDeclaration();
+ if (!ad || !ad->type)
+ return;
+
+ TypeIdentifier *ti = ad->type->isTypeIdentifier();
+ if (!ti || ti->idents.length != 0)
+ return;
+
+ if (TemplateTupleParameter *ttp = (*parameters)[0]->isTemplateTupleParameter())
{
- Dsymbol *s;
- if (Dsymbol::oneMembers(members, &s, ident) && s)
+ if (ti->ident == ttp->ident && ti->mod == 0)
+ {
+ //printf("found isAliasSeq %s %s\n", s->toChars(), ad->type->toChars());
+ isTrivialAliasSeq = true;
+ }
+ }
+ else if (TemplateTypeParameter *ttp = (*parameters)[0]->isTemplateTypeParameter())
+ {
+ if (ti->ident == ttp->ident)
{
- onemember = s;
- s->parent = this;
+ //printf("found isAlias %s %s\n", s->toChars(), ad->type->toChars());
+ isTrivialAlias = true;
}
}
}
sa = ((DotTemplateExp *)ea)->td;
goto Ldsym;
}
+ if (ea->op == TOKdot)
+ {
+ if (ScopeExp *se = ((DotExp *)ea)->e2->isScopeExp())
+ {
+ sa = se->sds;
+ goto Ldsym;
+ }
+ }
}
else if (sa)
{
{
Module *mi = minst; // instantiated -> inserted module
- if (global.params.useUnitTests ||
- global.params.debuglevel)
+ if (global.params.useUnitTests)
{
// Turn all non-root instances to speculative
if (mi && !mi->isRoot())
objectToBuffer(arg);
}
}
+ else if (Parameter *p = isParameter(oarg))
+ {
+ p->accept(this);
+ }
else if (!oarg)
{
buf->writestring("NULL");
*/
e = expressionSemantic(e, sc); // do this before turning on noaccesscheck
- sym->size(e->loc); // do semantic of type
+ if (!sym->determineFields())
+ {
+ error(e->loc, "unable to determine fields of `%s` because of forward references", toChars());
+ }
Expression *e0 = NULL;
Expression *ev = e->op == TOKtype ? NULL : e;
// Probably should cache this information in sym rather than recompute
StructDeclaration *s = sym;
- sym->size(Loc()); // give error for forward references
+ if (sym->members && !sym->determineFields() && sym->type != Type::terror)
+ error(sym->loc, "no size because of forward references");
+
for (size_t i = 0; i < s->fields.length; i++)
{
Declaration *d = s->fields[i];
bool literal; // this template declaration is a literal
bool ismixin; // template declaration is only to be used as a mixin
bool isstatic; // this is static template declaration
+ bool isTrivialAliasSeq; // matches `template AliasSeq(T...) { alias AliasSeq = T; }
+ bool isTrivialAlias; // matches `template Alias(T) { alias Alias = T; }
Prot protection;
int inuse; // for recursive expansion detection
s = imp->mod;
}
+ // https://issues.dlang.org/show_bug.cgi?id=16044
+ if (Package *p = s->isPackage())
+ {
+ if (Module *pm = p->isPackageMod())
+ s = pm;
+ }
+
ScopeDsymbol *sds = s->isScopeDsymbol();
if (!sds || sds->isTemplateDeclaration())
{
}
}
+ // https://issues.dlang.org/show_bug.cgi?id=20915
+ // skip version and debug identifiers
+ if (sm->isVersionSymbol() || sm->isDebugSymbol())
+ return 0;
+
//printf("\t[%i] %s %s\n", i, sm->kind(), sm->toChars());
if (sm->ident)
{
if (tf->isreturn && !tf->isref && !tf->next->hasPointers())
{
- ::error(loc, "function type `%s` has `return` but does not return any indirections", tf->toChars());
+ tf->isreturn = false;
}
}
if (0 && !tf->isref)
{
StorageClass stc = fparam->storageClass & (STCref | STCout);
- ::error(loc, "parameter %s is `return %s` but function does not return by ref",
+ ::error(loc, "parameter `%s` is `return %s` but function does not return by `ref`",
fparam->ident ? fparam->ident->toChars() : "",
stcToChars(stc));
errors = true;
}
else if (!tf->isref && tf->next && !tf->next->hasPointers())
{
- ::error(loc, "parameter %s is `return` but function does not return any indirections",
- fparam->ident ? fparam->ident->toChars() : "");
- errors = true;
+ fparam->storageClass &= STCreturn; // https://issues.dlang.org/show_bug.cgi?id=18963
}
}
}
const char *toChars();
void addMember(Scope *sc, ScopeDsymbol *sds);
const char *kind() const;
+ DebugSymbol *isDebugSymbol() { return this; }
void accept(Visitor *v) { v->visit(this); }
};
const char *toChars();
void addMember(Scope *sc, ScopeDsymbol *sds);
const char *kind() const;
+ VersionSymbol *isVersionSymbol() { return this; }
void accept(Visitor *v) { v->visit(this); }
};
--- /dev/null
+module pkg16044;
+
+int test1;
+int test2;
--- /dev/null
+module pkg16044.sub;
+
+int test3;
+int test4;
--- /dev/null
+// REQUIRED_ARGS: -Icompilable/imports
+// EXTRA_FILES: imports/pkg16044/package.d imports/pkg16044/sub/package.d
+module issue16044; // https://issues.dlang.org/show_bug.cgi?id=16044
+
+import pkg16044;
+import pkg16044.sub;
+
+static assert([__traits(allMembers, pkg16044)] == ["object", "test1", "test2"]);
+static assert([__traits(allMembers, pkg16044.sub)] == ["object", "test3", "test4"]);
--- /dev/null
+module issue20915;
+
+// prior to the PR adding this test case,
+// locally defined version and debug idents were included.
+version = illegal;
+debug = illegal;
+
+alias Seq(T...) = T;
+
+static assert (__traits(allMembers, issue20915) == Seq!("object", "Seq"));
--- /dev/null
+// https://issues.dlang.org/show_bug.cgi?id=21813
+Target.OS defaultTargetOS()
+{
+ return Target.OS.linux;
+}
+
+struct Target
+{
+ enum OS { linux }
+ OS os = defaultTargetOS();
+ void deinitialize() { this = this.init; }
+ @property isPOSIX() scope @nogc { }
+}
--- /dev/null
+// https://issues.dlang.org/show_bug.cgi?id=21813
+Target.OS defaultTargetOS()
+{
+ return Target.OS.linux;
+}
+
+struct Target
+{
+ enum OS { linux }
+ OS os = defaultTargetOS();
+ @property isPOSIX() scope @nogc { }
+}
+
--- /dev/null
+// https://issues.dlang.org/show_bug.cgi?id=19415
+
+struct S
+{
+ int x;
+ S foo() return { return S(x); }
+ this(this) @disable;
+}
+
+S bar()
+{
+ S s;
+ return s; // Error: struct `S` is not copyable because it is annotated with @disable
+}
--- /dev/null
+// https://issues.dlang.org/show_bug.cgi?id=20894
+
+mixin template MT()
+{
+ int a;
+ alias b = char;
+ void c() {}
+}
+
+struct S
+{
+ mixin MT mt;
+}
+
+void main()
+{
+ auto r = S();
+ enum c = S();
+
+ foo!(S.mt);
+ foo!(r.mt);
+ foo!(c.mt); // OK <- ICE
+
+ foo!(mixin("S.mt"));
+ foo!(mixin("r.mt")); // OK <- ICE
+ foo!(mixin("c.mt")); // OK <- ICE
+
+ // some checks
+ foo!(r.mt, c.mt);
+ foo!(mixin("r.mt"), c.mt);
+ foo!(r.mt, mixin("c.mt"));
+ foo!(S.mt, mixin("c.mt"));
+}
+
+alias Tup(T...) = T;
+
+void foo(A...)()
+{
+ static if (A.length == 2)
+ {
+ static assert(__traits(isSame, A[0], A[1]));
+ enum members = __traits(allMembers, A[0]);
+ static assert(members == __traits(allMembers, A[1]));
+ static assert(members == Tup!("a", "b", "c"));
+ }
+}
--- /dev/null
+// https://issues.dlang.org/show_bug.cgi?id=21812
+
+struct S(A...)
+{
+ A args;
+}
+
+static assert(__traits(allMembers, S!(int, float)) == AliasSeq!("args"));
+
+alias AliasSeq(T...) = T;
--- /dev/null
+/*
+TEST_OUTPUT:
+---
+fail_compilation/diag19196.d(11): Error: unable to determine fields of `B` because of forward references
+fail_compilation/diag19196.d(15): Error: template instance `diag19196.Foo!(B)` error instantiating
+---
+*/
+module diag19196;
+struct Foo(T)
+{
+ alias F = typeof(T.tupleof);
+}
+struct B
+{
+ Foo!B b;
+}
/* REQUIRED_ARGS: -dip25
TEST_OUTPUT:
---
-fail_compilation/test16228.d(22): Error: function type 'return int()' has 'return' but does not return any indirections
-fail_compilation/test16228.d(23): Error: function test16228.S.foo static member has no 'this' to which 'return' can apply
+fail_compilation/test16228.d(23): Error: function `test16228.S.bar` `static` member has no `this` to which `return` can apply
---
*/
+
// https://issues.dlang.org/show_bug.cgi?id=16228
int* wrap ( return ref int input )
int x;
int foo() return { return 3; }
- static ref int foo() return { return x; }
+ static ref int bar() return { return x; }
+}
+
+
+// https://issues.dlang.org/show_bug.cgi?id=18963
+
+T Identity(T)(return T t) { return t; }
+
+void bar(int i, void* p)
+{
+ Identity(p);
+ Identity(i);
}
--- /dev/null
+/* TEST_OUTPUT:
+---
+fail_compilation/test20919.d(12): Error: `__traits(getAttributes, int a)` does not give a valid type
+---
+*/
+// https://issues.dlang.org/show_bug.cgi?id=20919
+
+void foo(int a) {}
+
+static if (is(typeof(foo) params == __parameters))
+{
+ __traits(getAttributes, params) a;
+}