Skip to content

Commit

Permalink
Merge pull request #761 from mimiframework/eval
Browse files Browse the repository at this point in the history
Remove eval from defcomp macro
  • Loading branch information
lrennels authored Sep 12, 2020
2 parents 04a50cb + 986fff1 commit 51032df
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
16 changes: 5 additions & 11 deletions src/core/defcomp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ function add_variable(comp_id::ComponentId, name, datatype, dimensions, descript
end

function add_parameter(comp_def::ComponentDef, name, datatype, dimensions, description, unit, default)
if default !== nothing
if length(dimensions) != ndims(default)
error("Default value has different number of dimensions ($(ndims(dflt))) than parameter '$name' ($(length(dimensions)))")
end
end
p = ParameterDef(name, comp_def.comp_path, datatype, dimensions, description, unit, default)
comp_def[name] = p # adds to namespace and checks for duplicate
dirty!(comp_def)
Expand Down Expand Up @@ -261,19 +266,8 @@ macro defcomp(comp_name, ex)

@debug " index $(Tuple(dimensions)), unit '$unit', desc '$desc'"

if dflt !== nothing
dflt = Base.eval(Main, dflt)
if length(dimensions) != ndims(dflt)
error("Default value has different number of dimensions ($(ndims(dflt))) than parameter '$name' ($(length(dimensions)))")
end
end

@debug "before: datum type is $datum_type, which is of type $(typeof(datum_type))"
datum_type = (datum_type === nothing ? :Number : datum_type)
@debug "after: datum type is $datum_type, which is of type $(typeof(datum_type))"

addexpr(_generate_var_or_param(elt_type, name, datum_type, dimensions, dflt, desc, unit))

else
error("Unrecognized element type: $elt_type")
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_parametertypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ expr = :(
end
end
)
@test_throws LoadError eval(expr)
@test_throws UndefVarError eval(expr)

expr = :(
@defcomp BadComp2 begin
Expand All @@ -26,7 +26,7 @@ expr = :(
end
end
)
@test_throws LoadError eval(expr)
@test_throws UndefVarError eval(expr)

#
# Test that the old type parameterization syntax errors
Expand Down

0 comments on commit 51032df

Please sign in to comment.