Skip to content

Commit

Permalink
Resolve let! not working on uninferable types
Browse files Browse the repository at this point in the history
Resolves #4
Use ValueWrapper trick again and initialize immediately with before_each 
hook.
  • Loading branch information
icy-arctic-fox committed Jan 15, 2020
1 parent 7868755 commit c48b9ed
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/spectator/dsl/values.cr
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@ module Spectator
end

macro let!(name, &block)
# TODO: Doesn't work with late-defined values (let).
@%value = {{yield}}
@%wrapper : ::Spectator::ValueWrapper?

def %wrapper
{{block.body}}
end

before_each do
@%wrapper = ::Spectator::TypedValueWrapper.new(%wrapper)
end

def {{name.id}}
@%value
@%wrapper.as(::Spectator::TypedValueWrapper(typeof(%wrapper))).value
end
end

Expand Down

0 comments on commit c48b9ed

Please sign in to comment.