From 9e57b77d45915446a7d03750d038fc76c5ad3425 Mon Sep 17 00:00:00 2001 From: Gregor Kappler Date: Thu, 5 Nov 2020 00:48:03 +0100 Subject: [PATCH] Either constructor check if all options have matching result_type --- src/CombinedParsers.jl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/CombinedParsers.jl b/src/CombinedParsers.jl index 10461fc..5532afa 100644 --- a/src/CombinedParsers.jl +++ b/src/CombinedParsers.jl @@ -2430,8 +2430,14 @@ Either(p::P) where P = Either{T}(p) where T = Either{either_state_type(typeof(p)),T}(p) -Either{T}(p...) where {T} = - Either{either_state_type(Vector{Any}),T}(Any[parser.(p)...]) +function Either{T}(p_...) where {T} + p = Any[parser.(p_)...] + for x in p + result_type(x) <: T || error("$(result_type(x))<:$T") + end + Either{either_state_type(Vector{Any}),T}(p) +end + function Either(x...; kw...) Either(Any[ (parser(y) for y in x)..., (with_name(k,v) for (k,v) in kw)... ]) end