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:
Michael Miller 2022-12-09 02:16:16 -07:00
parent 47a62ece78
commit bd44b5562e
No known key found for this signature in database
GPG key ID: AC78B32D30CE34A2

View file

@ -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