mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Possible fix for GitLab issue 80
Remove `is_a?` check on line 425. Replace with alternate logic that achieves the same thing. The `{{type}}` in `is_a?` was causing a compiler bug. I'm unsure of the root cause, but this works around it.
This commit is contained in:
parent
47a62ece78
commit
bd44b5562e
1 changed files with 15 additions and 9 deletions
|
@ -422,12 +422,15 @@ module Spectator
|
||||||
# If successful, which it will be in most cases, return it.
|
# If successful, which it will be in most cases, return it.
|
||||||
# The caller will receive a properly typed value without unions or other side-effects.
|
# The caller will receive a properly typed value without unions or other side-effects.
|
||||||
%cast = %value.as?({{type}})
|
%cast = %value.as?({{type}})
|
||||||
if %cast.is_a?({{type}})
|
|
||||||
|
{% if fail_cast == :nil %}
|
||||||
%cast
|
%cast
|
||||||
else
|
{% elsif fail_cast == :raise %}
|
||||||
{% if fail_cast == :nil %}
|
# Check if nil was returned by the stub and if its okay to return it.
|
||||||
nil
|
if %value.nil? && {{type}}.nilable?
|
||||||
{% elsif fail_cast == :raise %}
|
# Value was nil and nil is allowed to be returned.
|
||||||
|
%cast.as({{type}})
|
||||||
|
elsif %cast.nil?
|
||||||
# The stubbed value was something else entirely and cannot be cast to the return type.
|
# The stubbed value was something else entirely and cannot be cast to the return type.
|
||||||
# There's something weird going on (compiler bug?) that sometimes causes this class lookup to fail.
|
# There's something weird going on (compiler bug?) that sometimes causes this class lookup to fail.
|
||||||
%type = begin
|
%type = begin
|
||||||
|
@ -436,10 +439,13 @@ module Spectator
|
||||||
"<Unknown>"
|
"<Unknown>"
|
||||||
end
|
end
|
||||||
raise TypeCastError.new("#{_spectator_stubbed_name} received message #{ {{call}} } and is attempting to return a `#{%type}`, but returned type must be `#{ {{type}} }`.")
|
raise TypeCastError.new("#{_spectator_stubbed_name} received message #{ {{call}} } and is attempting to return a `#{%type}`, but returned type must be `#{ {{type}} }`.")
|
||||||
{% else %}
|
else
|
||||||
{% raise "fail_cast must be :nil, :raise, or :no_return, but got: #{fail_cast}" %}
|
# Types match and value can be returned as cast type.
|
||||||
{% end %}
|
%cast
|
||||||
end
|
end
|
||||||
|
{% else %}
|
||||||
|
{% raise "fail_cast must be :nil, :raise, or :no_return, but got: #{fail_cast}" %}
|
||||||
|
{% end %}
|
||||||
{% end %}
|
{% end %}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue