Skip to content

Commit a3f839a

Browse files
committed
Fix parsing issue
1 parent 56e47a0 commit a3f839a

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

src/symbolic_dimensions.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,14 +414,11 @@ module SymbolicUnits
414414
if ex.head == :call
415415
ex.args[2:end] = map(map_to_scope, ex.args[2:end])
416416
return ex
417-
elseif ex.head == :tuple
418-
ex.args[:] = map(map_to_scope, ex.args)
419-
return ex
420417
elseif ex.head == :. && ex.args[1] == :Constants
421418
@assert ex.args[2] isa QuoteNode
422419
return lookup_constant(ex.args[2].value)
423420
else
424-
throw(ArgumentError("Unexpected expression: $ex. Only `:call`, `:tuple`, and `:.` (for `SymbolicConstants`) are expected."))
421+
throw(ArgumentError("Unexpected expression: $ex. Only `:call` and `:.` (for `SymbolicConstants`) are expected."))
425422
end
426423
end
427424
function map_to_scope(sym::Symbol)

src/uparse.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,11 @@ function map_to_scope(ex::Expr)
6666
if ex.head == :call
6767
ex.args[2:end] = map(map_to_scope, ex.args[2:end])
6868
return ex
69-
elseif ex.head == :tuple
70-
ex.args[:] = map(map_to_scope, ex.args)
71-
return ex
7269
elseif ex.head == :. && ex.args[1] == :Constants
7370
@assert ex.args[2] isa QuoteNode
7471
return lookup_constant(ex.args[2].value)
7572
else
76-
throw(ArgumentError("Unexpected expression: $ex. Only `:call`, `:tuple`, and `:.` (for `Constants`) are expected."))
73+
throw(ArgumentError("Unexpected expression: $ex. Only `:call` and `:.` (for `Constants`) are expected."))
7774
end
7875
end
7976
function map_to_scope(sym::Symbol)

test/unittests.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -462,26 +462,26 @@ end
462462
@test utime(z) == 1
463463
@test ustrip(z) 60 * 60 * 24 * 365.25
464464

465-
# Test that `u_str` respects original type:
466-
@test typeof(u"1") == Int
467-
@test typeof(u"1f0") == Float32
465+
# Test type stability of extreme range of units
466+
@test typeof(u"1") == DEFAULT_QUANTITY_TYPE
467+
@test typeof(u"1f0") == DEFAULT_QUANTITY_TYPE
468468
@test typeof(u"s"^2) == DEFAULT_QUANTITY_TYPE
469469
@test typeof(u"") == DEFAULT_QUANTITY_TYPE
470470
@test typeof(u"Gyr") == DEFAULT_QUANTITY_TYPE
471471
@test typeof(u"fm") == DEFAULT_QUANTITY_TYPE
472472
@test typeof(u"fm"^2) == DEFAULT_QUANTITY_TYPE
473473

474-
# Can also use tuples:
475-
@test typeof(u"(m, s)") == Tuple{DEFAULT_QUANTITY_TYPE, DEFAULT_QUANTITY_TYPE}
474+
@test_throws ErrorException eval(:(u":x"))
476475

477-
@test_throws LoadError eval(:(u"x"))
478476
VERSION >= v"1.9" && @test_throws "Symbol x not found" uparse("x")
479477
VERSION >= v"1.9" && @test_throws "Symbol c found in `Constants` but not `Units`" uparse("c")
480478
VERSION >= v"1.9" && @test_throws "Unexpected expression" uparse("import ..Units")
479+
VERSION >= v"1.9" && @test_throws "Unexpected expression" uparse("(m, m)")
481480
@test_throws LoadError eval(:(us"x"))
482481
VERSION >= v"1.9" && @test_throws "Symbol x not found" sym_uparse("x")
483482
VERSION >= v"1.9" && @test_throws "Symbol c found in `SymbolicConstants` but not `SymbolicUnits`" sym_uparse("c")
484483
VERSION >= v"1.9" && @test_throws "Unexpected expression" sym_uparse("import ..Units")
484+
VERSION >= v"1.9" && @test_throws "Unexpected expression" sym_uparse("(m, m)")
485485
end
486486

487487
@testset "Constants" begin

0 commit comments

Comments
 (0)