mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 05:00:16 +03:00

* Implement test case for Issue 24022 * [FIX] Issue 24022 Bug investigation info ====================== Currently (before this fix) on attempt to use `enum` declared as `typedef enum {A=1} E;` as type of argument in D function, it (`enum`) will be resolved as `kind=attribute` on during semantic analysis for D ([typesem.d](5e1e97078f/compiler/src/dmd/typesem.d (L1504)
)), but it have to be resolved as type. The `enum` declared this way is handled by this [code](5e1e97078f/compiler/src/dmd/cparse.d (L1907)
), and `declareTag` returns the attribute instead of type, but later, there is [code that create alias for attribute](5e1e97078f/compiler/src/dmd/cparse.d (L1918C29-L1918C79)
), though, it seems, that alias have to be created to type, instead of attribute. Investigating [declareTag](5e1e97078f/compiler/src/dmd/cparse.d (L1715)
) function shows that the returned value changed by call to [applySpecifier](5e1e97078f/compiler/src/dmd/cparse.d (L5234)
), that applies `AlignDeclaration` when `if (!specifier.packalign.isDefault())`. Fix info ======== With this commit the alias will be created to TypeTag, instead of attribute produced by declared tag. Also, the code simplified, because there is no more need for special handling of enums in modified piece of code.
30 lines
587 B
D
30 lines
587 B
D
// https://issues.dlang.org/show_bug.cgi?id=24022
|
|
// EXTRA_FILES: imports/imp24022.c
|
|
import imports.imp24022;
|
|
|
|
auto some_d_func(E v) {
|
|
return v;
|
|
}
|
|
|
|
auto some_d_other_func() {
|
|
const struct R {
|
|
E r;
|
|
this(in E vparam) { r = vparam; }
|
|
}
|
|
return R(A);
|
|
}
|
|
|
|
void main(string[] args) {
|
|
E expected = E.A;
|
|
E res = some_d_func(A);
|
|
assert (res == A);
|
|
assert (res == expected);
|
|
|
|
res = some_d_func(E.B);
|
|
assert (res == B);
|
|
assert (res == E.B);
|
|
|
|
auto res2 = some_d_other_func();
|
|
assert (res2.r == A);
|
|
assert (res2.r == expected);
|
|
}
|