From e25d8098937b4ba9728ec6f8fcab731c4e8a84d1 Mon Sep 17 00:00:00 2001 From: Alexander Plavin Date: Mon, 20 Jun 2022 01:27:10 +0300 Subject: [PATCH] throw if no fields --- src/utils.jl | 1 + test/runtests.jl | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/utils.jl b/src/utils.jl index 5f4e9936..04ca24b1 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -33,6 +33,7 @@ end map_params_as_tuple_fallback(f, ::Type{T}) where {T<:Tup} = map(f, fieldtypes(T)) buildfromschema(initializer::F, ::Type{T}) where {F, T} = buildfromschema(initializer, T, staticschema(T)) +buildfromschema(initializer, ::Type, ::Type{NamedTuple{(), Tuple{}}}) = error("Only structs with fields are supported") """ StructArrays.buildfromschema(initializer, T[, S]) diff --git a/test/runtests.jl b/test/runtests.jl index aabf8c90..19d789cd 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -433,6 +433,9 @@ end t = StructVector([(a=1,), (a=missing,)])::StructVector @test isequal(t.a, [1, missing]) @test eltype(t) <: NamedTuple{(:a,)} + + @test_throws Exception StructArray([nothing]) + @test_throws Exception StructArray([1, 2, 3]) end @testset "tuple case" begin