D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20731 - checkaction=context fails for structs with 'alias <slice> this'
Summary: checkaction=context fails for structs with 'alias <slice> this'
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: druntime (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2020-04-13 02:48 UTC by moonlightsentinel
Modified: 2020-04-13 04:32 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description moonlightsentinel 2020-04-13 02:48:39 UTC
The following snippet causes a compilation failure / wrong formatting depending on whether a is const/mutable:

----------------------------------------------
struct S
{
    int[2] arr;
    int[] get() { return arr[]; }
    alias get this;
}

const a = S([1, 2]);
assert(a == S([3, 4]);
-----------------------------------------------

Mutable: "[1, 2] != [3, 4]" instead of "S([1, 2]) != S([3, 4])".

Const: "Mutable method `get` is not callable using a `const` object!"
Comment 1 Dlang Bot 2020-04-13 02:54:23 UTC
@MoonlightSentinel created dlang/druntime pull request #3029 "Fix Issue 20731 - checkaction=context fails for structs with 'alias <slice> this'" fixing this issue:

- Fix Issue 20731 - checkaction=context fails for structs with 'alias <slice> this'
  
  Exclude structs wich are implicitly convertible to a slice due to `alias this`".

https://github.com/dlang/druntime/pull/3029
Comment 2 Dlang Bot 2020-04-13 04:32:01 UTC
dlang/druntime pull request #3029 "Fix Issue 20731 - checkaction=context fails for structs with 'alias <slice> this'" was merged into stable:

- d15e8ec1ecd8a5c917f9f22c3e4ae2986694ec7d by MoonlightSentinel:
  Fix Issue 20731 - checkaction=context fails for structs with 'alias <slice> this'
  
  Exclude structs wich are implicitly convertible to a slice due to `alias this`".

https://github.com/dlang/druntime/pull/3029