mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Fix detection of nullable return type from stubbed method
This commit is contained in:
parent
380d721fad
commit
7923eb3ad0
1 changed files with 10 additions and 10 deletions
|
@ -130,7 +130,7 @@ module Spectator
|
||||||
if %stub = _spectator_find_stub(%call)
|
if %stub = _spectator_find_stub(%call)
|
||||||
# Cast the stub or return value to the expected type.
|
# Cast the stub or return value to the expected type.
|
||||||
# This is necessary to match the expected return type of the original method.
|
# This is necessary to match the expected return type of the original method.
|
||||||
_spectator_cast_stub_value(%stub, %call, typeof({{original}}), {{method.return_type && method.return_type.resolve < Nil || false}})
|
_spectator_cast_stub_value(%stub, %call, typeof({{original}}), {{method.return_type && method.return_type.resolve <= Nil || method.return_type.is_a?(Union) && method.return_type.types.map(&.resolve).includes?(Nil)}})
|
||||||
else
|
else
|
||||||
# Delegate missing stub behavior to concrete type.
|
# Delegate missing stub behavior to concrete type.
|
||||||
_spectator_stub_fallback(%call, typeof({{original}})) do
|
_spectator_stub_fallback(%call, typeof({{original}})) do
|
||||||
|
@ -221,7 +221,7 @@ module Spectator
|
||||||
# This is necessary to match the expected return type of the original method.
|
# This is necessary to match the expected return type of the original method.
|
||||||
{% if method.return_type %}
|
{% if method.return_type %}
|
||||||
# Return type restriction takes priority since it can be a superset of the original implementation.
|
# Return type restriction takes priority since it can be a superset of the original implementation.
|
||||||
_spectator_cast_stub_value(%stub, %call, {{method.return_type}}, {{method.return_type.resolve < Nil}})
|
_spectator_cast_stub_value(%stub, %call, {{method.return_type}}, {{method.return_type.resolve <= Nil || method.return_type.is_a?(Union) && method.return_type.types.map(&.resolve).includes?(Nil)}})
|
||||||
{% elsif !method.abstract? %}
|
{% elsif !method.abstract? %}
|
||||||
# The method isn't abstract, infer the type it returns without calling it.
|
# The method isn't abstract, infer the type it returns without calling it.
|
||||||
_spectator_cast_stub_value(%stub, %call, typeof({{original}}))
|
_spectator_cast_stub_value(%stub, %call, typeof({{original}}))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue