Issue 24366 - [REG]static foreach can drop last element with alias reassignment
Summary: [REG]static foreach can drop last element with alias reassignment
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 regression
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-02-01 20:03 UTC by crazymonkyyy
Modified: 2024-10-12 18:43 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description crazymonkyyy 2024-02-01 20:03:57 UTC
alias seq(T...)=T;
template foo(T...){
    alias bar=seq!();
    static foreach(i,A;T){
        alias bar_(alias B:A)=bar;
        bar=seq!(bar_!A,A);
    }
    alias foo=bar;
}
void main(){
    import std;
    alias foobar=foo!(int,bool,float);
    foobar.stringof.writeln;
}

expected: (int,bool,float)
actaul: (int,bool)


```
2.095.1 to 2.100.2: Success with output: (int, bool, float)
Since      2.101.2: Success with output: (int, bool)
```
Comment 1 Adam D. Ruppe 2024-10-12 18:43:39 UTC
We identified the cause in OpenD as dsymbolsem.d look for "Try AliasSeq optimization"

Commenting that out fixes the problem.

    // Try AliasSeq optimization
    /+
    // actually don't because it is cause of https://issues.dlang.org/show_bug.cgi?id=24366
    if (auto ti = ds.type.isTypeInstance())
    {
        if (!ti.tempinst.findTempDecl(sc, null))
            return errorRet();
        if (auto tempinst = isAliasSeq(sc, ti))
        {
            s = aliasAssignInPlace(sc, tempinst, aliassym);
            if (!s)
                return errorRet();
            goto Lsymdone;
        }
    }
    +/