Lazy.jl icon indicating copy to clipboard operation
Lazy.jl copied to clipboard

@switch fails when matching fields of struct

Open dm3 opened this issue 7 years ago • 2 comments

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

dm3 avatar Jan 08 '18 15:01 dm3

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 avatar Aug 08 '20 20:08 NightMachinery

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

NightMachinery avatar Aug 08 '20 22:08 NightMachinery