-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Closed
Description
See discussion in https://discourse.julialang.org/t/no-automatic-type-promotion-for-parametric-structs/62664/1
When using different (but convertible) types in a constructor, for "standard" structs the types get converted automatically, e.g.
struct Struct1
x:: Float64
y
end
s1b = Struct1(5, 1) # output: Struct1b(5.0, 1)
However, this is not done if the struct has a type parameter (even if this parameter is for a different field), instead I get a MethodError:
struct Struct2{T}
x:: Float64
y:: T
end
s2b = Struct2(5, 1) # MethodError, I would expect Struct2{Int64}(5.0, 1)
s2c = Struct2(5.0, 1) # this works, output: Struct2{Int64}(5.0, 1)
This behavior is confusing for me, I would expect that type promotion is also done for parametric structs. Or is there a good reason for it which I am not aware of?
Metadata
Metadata
Assignees
Labels
No labels