diff --git a/src/layers/basic.jl b/src/layers/basic.jl index a8cb0a9d1c..3c615ae06d 100644 --- a/src/layers/basic.jl +++ b/src/layers/basic.jl @@ -562,9 +562,10 @@ function Parallel(connection; kw...) if :layers in keys(layers) || :connection in keys(layers) throw(ArgumentError("a Parallel layer cannot have a named sub-layer called `connection` or `layers`")) end - isempty(layers) && return Parallel(connection, ()) Parallel(connection, layers) end +Parallel(connection, layers::Union{Tuple{}, @NamedTuple{}}) = + throw(ArgumentError("cannot construct a Parallel layer with no sub-layers")) @layer :expand Parallel diff --git a/test/layers/basic.jl b/test/layers/basic.jl index d09579c257..8e33340611 100644 --- a/test/layers/basic.jl +++ b/test/layers/basic.jl @@ -266,11 +266,8 @@ using Flux: activations @test_throws ArgumentError Parallel(hcat, inv)() @test_throws ArgumentError Parallel(hcat, inv, sqrt)() - # zero layers -- not useful... can we make this an error without a breaking change? - @test Parallel(hcat) isa Parallel{typeof(hcat), Tuple{}} # not a NamedTuple - @test Parallel(hcat)(1) == hcat() - - @test Parallel(hcat, inv)(2) == hcat(1/2) # still calls connection once. + # zero layers -- not useful... now made an error + @test_throws ArgumentError Parallel(hcat) end @testset "connection is called once" begin