D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6936 - type combination is not commutative
Summary: type combination is not commutative
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-12 04:06 UTC by timon.gehr
Modified: 2024-12-13 17:56 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description timon.gehr 2011-11-12 04:06:19 UTC
Tested with DMD 2.056.

const(int[]) x;
const(int)[] y;

static assert(is(typeof(1?x:y) == typeof(1?y:x))); // fail.


Error: static assert  (is(const(int)[] == const(int[]))) is false

The static assertion should pass.

I suggest the common type in this case should be const(int)[]. That is consistent with how type combination works for basic types.
Comment 1 hsteoh 2014-07-19 01:44:26 UTC
Isn't this more a problem with type inference in the ternary '?' operator?
Comment 2 Jonathan M Davis 2014-07-19 02:17:22 UTC
(In reply to hsteoh from comment #1)
> Isn't this more a problem with type inference in the ternary '?' operator?

Yes. The ternary operator currently, incorrectly uses the type of its last argument rather than the common type of the second and third arguments.

It's essentially the same bug as issue# 3543, but this is with arrays, whereas 3543 specifically talks about classes and interfaces, so I'm not sure if it's actually a duplicate.
Comment 3 hsteoh 2014-07-22 14:25:21 UTC
Recently Kenji fixed array type deduction to work correctly with base classes. But I guess it still doesn't work properly with common interfaces, or, in this case, const-ness.
Comment 4 dlangBugzillaToGithub 2024-12-13 17:56:54 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18380

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB