[Issue 24345] New: Issue with `alias this = xyz` inside structs.
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Jan 19 06:55:38 UTC 2024
https://issues.dlang.org/show_bug.cgi?id=24345
Issue ID: 24345
Summary: Issue with `alias this = xyz` inside structs.
Product: D
Version: D2
Hardware: All
URL: http://dlang.org/
OS: All
Status: NEW
Severity: major
Priority: P3
Component: dmd
Assignee: nobody at puremagic.com
Reporter: codedan at hotmail.com
Example code:
```d
module app;
import std;
void main() {
auto x = new Derived(10, 20);
}
struct Base {
int a;
}
struct Derived
{
Base base;
int b;
alias this = base;
@disable this();
// `a` is not available for use with constructor parameters.
//
this( typeof(a) _a, typeof(b) _b ) {
//
// inside the body of the constructor, `a` is available!
//
a = _a;
b = _b;
writeln( a, ", ", b );
}
}
```
Error:
`Error: undefined identifier a`
Problem:
The compiler can't find the symbol `a` in the constructor parameters, although
the symbol was "imported" into the struct scope by using `alias this = base;`.
--
More information about the Digitalmars-d-bugs
mailing list