MikeInnes / Lazy.jl

I was gonna maintain this package, but then I got high
Other
470 stars 54 forks source link

@switch fails when matching fields of struct #74

Open dm3 opened 6 years ago

dm3 commented 6 years ago

Julia 0.6.2, Lazy 0.12

julia> struct Ints x :: Int end

julia> z = Ints(1)
Ints(1)

julia> Lazy.@switch z.x begin 1; println("one") end
ERROR: TypeError: non-boolean (Int64) used in boolean context

@switch on variables works as expected:

julia> x = 1
1

julia> Lazy.@switch x begin 1; println("one") end
one
NightMachinery commented 4 years ago

This problem doesn't seem fixed in the latest versions. Is there a workaround? Trying someStruct.someField == _ also gives the error ERROR: LoadError: syntax: all-underscore identifier used as rvalue around /Users/evar/.julia/packages/Lazy/KYseE/src/macros.jl:45.

NightMachinery commented 4 years ago

A nice alternative is https://thautwarm.github.io/MLStyle.jl/latest/ .