Bug 24325 – Type inference has precedence over written type when using `static`

Status
NEW
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2024-01-08T10:52:17Z
Last change time
2024-12-13T19:32:28Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
Marcelo Silva Nascimento Mancini
Moved to GitHub: dmd#20378 →

Comments

Comment #0 by msnmancini — 2024-01-08T10:52:17Z
``` void main() { alias CBType = string function(); static immutable CBType[] callbacks = [ (){return null;}, (){return "hello";} ]; } ``` If `static immutable` is dropped, it compiles. That shows the `CBType[]` is being ignored. This also happens with associative arrays.
Comment #1 by nick — 2024-01-08T16:23:02Z
Error with v2.106 is: Error: cannot implicitly convert expression `__lambda1` of type `typeof(null) function() pure nothrow @nogc @safe` to `immutable(string function())` So `CBType[]` is not ignored, but it is not used to infer the type of the template lambda. > If `static immutable` is dropped, it compiles Or when just `static` is dropped.
Comment #2 by robert.schadek — 2024-12-13T19:32:28Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20378 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB