New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue 3438 - default ctor with all default arguments must be rejected #1397
Conversation
The diff view is unhelpful unfortunately. |
https://github.com/D-Programming-Language/dmd/pull/1397/files?w=0 |
This is not good change.
|
Ok let me just see if I got all the test-cases before I commit. These are failures for structs: struct F1 { this(int x = 1) { } }
struct F2 { this(int x = 1, ...) { } }
struct F3 { this(...) { } }
struct F4 { this(int[] x...) { } }
struct F5 { @disable this(int x = 1); } And the new I'll fix classes as you mentioned. Is this ok so far? |
Seems OK. |
Damn I have no idea what happened to this, I guess we just forgot about it 9 months ago. I'll rebase it now. |
Updated. Requesting review. @9rnsr |
This is strange, why would merging fail? s/would/does |
I finally think rejecting the definition of zero-arg callable constructors is not good, because it would reject correct use cases. Instead, how about to reject the call of the constructors with zero-arguments. For example: struct X { this(int x = 0) {} } // If only X(num) is used, this is still valid definition.
// Reporting warning for the definition would be useful
struct S { this(int[] values...) {} } // I think this is still legitimate signature
// In this case, reporting warning for the definition is not good.
void main() {
S s1; // OK, default constructed
S s2 = S(10); // OK, constructor is called (I think this is legitimate use case)
S s3 = S(); // Changed to NG instead of the silent default construction
} |
I don't see the point of that. Why allow defining a function with all-default args, when it can never be called like that? |
@yebblies I think that immediately disallow |
Sure, making it a warning first would be a good idea. But the whole point is that code isn't valid because the default argument is dead code. |
And, |
But this is still problematic as the user would expect the ctor would be called without arguments. See: void test(int[] values...) { }
void main()
{
test(); // works fine
} Compared to: struct S
{
this(int[] values...) { assert(0); } // doesn't get called
}
void main()
{
auto s = S();
}
@9rnsr: You already broke a ton of code with your static opCall change.. |
Hmm. The essential issue I think is that, if struct S {
this(int x = 0, int y = 0) {} // A
this(int[] values...) {} // B
} The definition of A can be immediately disallowed - removing the first default argument won't break existing code meaning, but disallowing B would be overkill, because it would need more rewriting of the body of B. |
I guess variadic-style arguments in a ctor are used rarely enough that we could implement a special-case for them. In the vast majority of cases when users complain about "ctor not being called" they provide the example A. |
Hmm I'm getting this in the test-suite for x64 platforms:
But we're not allowed to import into druntime in the DMD test-suite. What should I use as a workaround? |
That's not true, importing druntime is fine. Importing phobos is the problematic one. |
Ah, ok. Updated then. |
Pinging for approval. |
Are we planning on going forward with this? I'll rebase and reopen if it's a go. |
http://d.puremagic.com/issues/show_bug.cgi?id=3438