You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A struct with a parametrized type, who is also the return type of a function parameter (or argument) is not making the compiler happy. No matter if the function signature is exactly what is needed.
Steps to reproduce
Include relevant code snippet or link to code that did not work as expected.
# Needs a function as a parameterstruct Foo[T: AnyType, f1: fn () -> T]:
aliasone_generator= f1
# Needs a function as an argumentstruct Bar[T: AnyType]:
varone_generator: fn () -> T
fn__init__(inoutself, f1: fn () -> T):
self.one_generator = f1
# function to be passedfnreturns_one() -> Int:
return1fnmain() -> None:
varfoo= Foo[Int, returns_one]
# error: 'Foo' parameter #1 has 'fn() -> Int' type, but value has type 'fn() -> Int'varbar= Bar[Int](returns_one)
# error: invalid initialization: argument #1 cannot be converted from 'fn() -> Int' to 'fn() -> Int'
The problem goes away if I specify the return type to be a an Int instead of the type T. But this is not generic.
- What OS did you do install Mojo on ?
╭──────────────────┬─────────────────────────────────────╮
│ kernel-name │ Linux │
│ kernel-release │ 5.15.153.1-microsoft-standard-WSL2 │
│ kernel-version │ #1 SMP Fri Mar 29 23:14:13 UTC 2024 │
│ machine │ x86_64 │
│ operating-system │ GNU/Linux │
╰──────────────────┴─────────────────────────────────────╯
- Provide version information for Mojo by pasting the output of `mojo -v`
mojo 2024.7.2505 (defedaa4)
- Provide Modular CLI version by pasting the output of `modular -v`
modular 0.8.0 (39a426b5)
The text was updated successfully, but these errors were encountered:
Bug description
A struct with a parametrized type, who is also the return type of a function parameter (or argument) is not making the compiler happy. No matter if the function signature is exactly what is needed.
Steps to reproduce
The problem goes away if I specify the return type to be a an Int instead of the type T. But this is not generic.
But this is not generic :(
System information
The text was updated successfully, but these errors were encountered: