Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

8741 wrong code for struct member inititalited using struct ctor #1157

Merged
merged 1 commit into from

4 participants

@donc
Collaborator

Generate an error if we need to decide if it is a ctor or a struct literal, when we haven't determined the size yet (so that we don't know if if it has a constructor). Since this whole thing is happening in a trySemantic block, it will try again later when it has found the ctor, and at that point, it will compile without error.

The wording for the error message is not very good, but I think this only happens while errors are gagged, so the message will never be visible.

@donc
Collaborator

Fails test42.d

@donc donc closed this
@donc donc reopened this
@donc donc closed this
@donc
Collaborator

Rebased, trying to work out why github is so confused about this (there is only one commit in this pull request).

@donc donc reopened this
@don-clugston-sociomantic don-clugston-sociomantic Fix issue 8741 wrong code for struct member init using struct ctor
Generate an error if we need to decide if it is a ctor or not, when we
haven't determined the size yet.
39207df
@WalterBright WalterBright merged commit 8ad7a53 into D-Programming-Language:master
@donc donc deleted the donc:wrongcode8741struct_ctor branch
@ghost Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@ghost Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@ghost Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@ghost Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@CyberShadow
Collaborator

This pull request introduced a regression:
https://issues.dlang.org/show_bug.cgi?id=12665

Retracted, see issue discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 7, 2012
  1. @don-clugston-sociomantic @donc

    Fix issue 8741 wrong code for struct member init using struct ctor

    don-clugston-sociomantic authored donc committed
    Generate an error if we need to decide if it is a ctor or not, when we
    haven't determined the size yet.
This page is out of date. Refresh to see the latest.
Showing with 33 additions and 0 deletions.
  1. +11 −0 src/expression.c
  2. +22 −0 test/runnable/sdtor.d
View
11 src/expression.c
@@ -7922,6 +7922,17 @@ Expression *CallExp::semantic(Scope *sc)
{
ad = ((TypeStruct *)t1)->sym;
#if DMDV2
+
+ if (ad->sizeok == SIZEOKnone && !ad->ctor &&
+ ad->search(0, Id::ctor, 0))
+ {
+ // The constructor hasn't been found yet, see bug 8741
+ // This can happen if we are inferring type from
+ // from VarDeclaration::semantic() in declaration.c
+ error("cannot create a struct until its size is determined");
+ return new ErrorExp();
+ }
+
// First look for constructor
if (e1->op == TOKtype && ad->ctor && (ad->noDefaultCtor || arguments && arguments->dim))
{
View
22 test/runnable/sdtor.d
@@ -1166,6 +1166,7 @@ void test45()
}
/**********************************/
+// 3986
struct SiberianHamster
{
@@ -1180,6 +1181,26 @@ void test46()
}
/**********************************/
+// 8741
+
+struct Vec8741
+{
+ this(float x)
+ {
+ m[0] = x;
+ m[1] = 58;
+ }
+ float[2] m;
+ static Vec8741 zzz = Vec8741(7);
+}
+
+void test8741()
+{
+ assert(Vec8741.zzz.m[0] == 7);
+ assert(Vec8741.zzz.m[1] == 58);
+}
+
+/**********************************/
struct Segfault3984
{
@@ -2413,6 +2434,7 @@ int main()
test59();
test5737();
test6119();
+ test8741();
test6364();
test6499();
test60();
Something went wrong with that request. Please try again.