Skip to content

Commit

Permalink
fix improperly applied inherited field constraints (#77)
Browse files Browse the repository at this point in the history
* fix improperly applied inherited field constraints

* bump Project.toml

* fix comment
  • Loading branch information
jrevels authored Dec 28, 2022
1 parent 6fffcf5 commit b26aa87
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Legolas"
uuid = "741b9549-f6ed-4911-9fbf-4a1c0c97f0cd"
authors = ["Beacon Biosignals, Inc."]
version = "0.5.5"
version = "0.5.6"

[deps]
Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45"
Expand Down
8 changes: 5 additions & 3 deletions src/schemas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -461,16 +461,18 @@ function _generate_record_type_definitions(schema_version::SchemaVersion, record
field_definitions = Expr[]
field_assignments = Expr[]
for (fname, ftype) in pairs(record_fields)
fdef = :($fname::$(Base.Meta.quot(ftype)))
T = Base.Meta.quot(ftype)
fdef = :($fname::$T)
info = get(declared_field_infos, fname, nothing)
if !isnothing(info)
fstmt = info.statement
if info.parameterize
T = Symbol("_", string(fname, "_T"))
push!(type_param_defs, :($T <: $(info.type)))
push!(names_of_parameterized_fields, fname)
fdef = :($fname::$T)
fstmt = :($fname = $(fstmt.args[2]))
fstmt = :($fname = $(info.statement.args[2]))
else
fstmt = :($fname = convert($T, $(info.statement.args[2]))::$T)
end
push!(field_assignments, fstmt)
end
Expand Down
19 changes: 19 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,22 @@ end

# overwriting another module's reserved schema name is disallowed
@test_throws ArgumentError("A schema with this name was already declared by a different module: $A") @schema("a.cross", Cross)

#####
##### local field variable handling in record constructors (ref https://github.com/beacon-biosignals/Legolas.jl/issues/76)
#####

Legolas.@schema "unconstrained-field" UnconstrainedField

Legolas.@version UnconstrainedFieldV1 begin
field::Any
end

Legolas.@schema "constrained-field" ConstrainedField

Legolas.@version ConstrainedFieldV1 > UnconstrainedFieldV1 begin
field::Int = parse(Int, field)
end

c = ConstrainedFieldV1(field = "1")
@test c.field == 1

2 comments on commit b26aa87

@jrevels
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/74724

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.6 -m "<description of version>" b26aa87403eb73c9d42b24b2e39b71908d0cda56
git push origin v0.5.6

Please sign in to comment.