We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I get errors when trying to use Optional to wrap a capturing closure in an argument or a parameter. See example code below.
Optional
OptionalReg
The error is marked "TODO" but I didn't see an issue filed to fix this anywhere.
Blocking KERN-542. Tracing.mojo is using a workaround to avoid accepting a capturing closure as a parameter.
Test program:
# Change `OptionalReg` to `Optional` for a compiler crash struct StructWithFuncParam[func: OptionalReg[fn () capturing -> String] = None]: var s: String fn __init__(inout self): self.s = func.value()() fn print_me(inout self): print(self.s) struct StructWithFuncArg: var s: String fn __init__( inout self, func: OptionalReg[fn () capturing -> String] = None ): self.s = func.value()() fn print_me(inout self): print(self.s) fn main(): var f = "foo" @parameter fn foo() -> String: return f # error: 'kgen.param.constant' op cannot be used to materialize capturing closures; use `kgen.create_closure` instead var x = StructWithFuncParam[foo]() x.print_me() # CHECK: "foo" # error: TODO: capturing closures cannot be materialized as runtime values # var z = StructWithFuncArg(foo) # z.print_me()
mojo 0.0.0 (4bb704c4) modular 0.0.0 (4bb704c4) macOS Sonoma 14.5 (M3 Pro)
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Bug description
I get errors when trying to use
Optional
to wrap a capturing closure in an argument or a parameter. See example code below.Optional
capturing closure as parameter leads to compiler crashOptionalReg
capturing closure leads to error in pass managerOptional
capturing closure as argument leads to compile-time error messageThe error is marked "TODO" but I didn't see an issue filed to fix this anywhere.
Blocking KERN-542. Tracing.mojo is using a workaround to avoid accepting a capturing closure as a parameter.
Steps to reproduce
Test program:
System information
The text was updated successfully, but these errors were encountered: