Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Mooncake"
uuid = "da2b9cff-9c12-43a0-ae48-6db2b0edb7d6"
authors = ["Will Tebbutt, Hong Ge, and contributors"]
version = "0.4.152"
version = "0.4.153"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
12 changes: 2 additions & 10 deletions src/fwds_rvs_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,7 @@ function fdata(t::T) where {T}
end

function fdata(::Type{T}) where {T}
throw(
error(
"$T is a type. Perhaps you meant fdata_type($T) or fdata(instance_of_tangent)?"
),
)
error("$T is a type. Perhaps you meant fdata_type($T) or fdata(instance_of_tangent)?")
end

function fdata(t::T) where {T<:PossiblyUninitTangent}
Expand Down Expand Up @@ -539,11 +535,7 @@ function rdata(t::T) where {T}
end

function rdata(::Type{T}) where {T}
throw(
error(
"$T is a type. Perhaps you meant rdata_type($T) or rdata(instance_of_tangent)?"
),
)
error("$T is a type. Perhaps you meant rdata_type($T) or rdata(instance_of_tangent)?")
end

function rdata(t::T) where {T<:PossiblyUninitTangent}
Expand Down
38 changes: 3 additions & 35 deletions test/fwds_rvs_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,40 +158,8 @@ end
end
end

@testset "Error messages for types passed to accessor functions" begin
# Test that passing types to fdata throws helpful error message
@test_throws "Float64 is a type. Perhaps you meant fdata_type(Float64) or fdata(instance_of_tangent)?" fdata(
Float64
)
@test_throws "Int64 is a type. Perhaps you meant fdata_type(Int64) or fdata(instance_of_tangent)?" fdata(
Int64
)

# Test that passing types to rdata throws helpful error message
@test_throws "Float64 is a type. Perhaps you meant rdata_type(Float64) or rdata(instance_of_tangent)?" rdata(
Float64
)
@test_throws "Int64 is a type. Perhaps you meant rdata_type(Int64) or rdata(instance_of_tangent)?" rdata(
Int64
)

# Test with more complex types - using exact string matching since the message is deterministic
@test_throws "Vector{Float64} is a type. Perhaps you meant fdata_type(Vector{Float64}) or fdata(instance_of_tangent)?" fdata(
Vector{Float64}
)
@test_throws "Vector{Float64} is a type. Perhaps you meant rdata_type(Vector{Float64}) or rdata(instance_of_tangent)?" rdata(
Vector{Float64}
)

# Verify that existing functionality with instances still works
x = 5.0
t = zero_tangent(x)
@test fdata(t) isa NoFData
@test rdata(t) isa Float64

arr = [1.0, 2.0]
t_arr = zero_tangent(arr)
@test fdata(t_arr) isa Vector{Float64}
@test rdata(t_arr) isa NoRData
@testset "Helpful error messages for misuse of fdata and rdata" begin
@test_throws "Float64 is a type. Perhaps you meant" fdata(Float64)
@test_throws "Float64 is a type. Perhaps you meant" rdata(Float64)
end
end
Loading