From 5fc08dbbe45837d36bad282475517baea8f49524 Mon Sep 17 00:00:00 2001 From: ParadoxV5 Date: Fri, 15 Sep 2023 20:52:58 -0600 Subject: [PATCH] =?UTF-8?q?=E2=80=A6=20except=20now=20RBS=20broke=20becaus?= =?UTF-8?q?e=20we=20know=20too=20much?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/godot/array.rb | 5 ++++- lib/godot/mixins.rb | 2 +- lib/godot/ruby_language.rb | 2 +- lib/godot/variant.rb | 4 ++-- sig/array.rbs | 11 +++++------ sig/variant.rbs | 3 ++- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/godot/array.rb b/lib/godot/array.rb index 26db2a6..8dcd0f0 100644 --- a/lib/godot/array.rb +++ b/lib/godot/array.rb @@ -21,7 +21,10 @@ def self.from(enum, **kwargs) def self.[](*elems, **kwargs) array = new(**kwargs) array.resize(elems.size) - elems.each_with_index {|elem, index| array[index] = elem } + elems.each_with_index do|elem, index| + #@type var elem: untyped + array[index] = elem + end array end diff --git a/lib/godot/mixins.rb b/lib/godot/mixins.rb index 8ba63e0..0575688 100644 --- a/lib/godot/mixins.rb +++ b/lib/godot/mixins.rb @@ -1,5 +1,5 @@ module Godot - module Mixins + module Mixins %i[ NilClass TrueClass diff --git a/lib/godot/ruby_language.rb b/lib/godot/ruby_language.rb index 8f816bf..8438757 100644 --- a/lib/godot/ruby_language.rb +++ b/lib/godot/ruby_language.rb @@ -70,7 +70,7 @@ def _remove_named_global_constant(...) = Autoloads.remove_const(...) # bool _supports_documentation ( ) virtual const # void _thread_enter ( ) virtual # void _thread_exit ( ) virtual - # String _validate_path ( String path ) virtual const + # String _validate_path ( String path ) virtual const # # ? # void _finish ( ) virtual diff --git a/lib/godot/variant.rb b/lib/godot/variant.rb index 8addc88..4932662 100644 --- a/lib/godot/variant.rb +++ b/lib/godot/variant.rb @@ -26,7 +26,7 @@ def set(...) def method_missing(name, *args) # Zeroth, Ruby suffixes are special case name[-1] - when '=' + when '=' public_send(:[]=, # https://github.com/soutaro/steep/issues/914 name[..-1], #: ::String *args @@ -40,7 +40,7 @@ def method_missing(name, *args) self[name] rescue KeyError # Second, check methods - godot_send(name, *args) # `rescue` attaches `KeyError` cause if this raises + godot_send(name, *args) # `rescue` attaches `KeyError` cause if this raises end else godot_send(name, *args) # Same as in the `rescue KeyError` block, just without any `KeyError` causes diff --git a/sig/array.rbs b/sig/array.rbs index 41f7cec..171b7b7 100644 --- a/sig/array.rbs +++ b/sig/array.rbs @@ -2,16 +2,15 @@ module Godot class Variant #class AbstractArray[E < (Variant | bool)] < Variant # https://github.com/ruby/rbs/issues/1471 - class AbstractArray[unchecked out E < Variant] < Variant - - def self.from: [E < Variant] (_Each[E] enum, **bot kwargs) -> AbstractArray[E] - def self.[]: [E < Variant] (*E elems, **bot kwargs) -> AbstractArray[E] + class AbstractArray[unchecked out E < Variant] < Variant + def self.from: [E < Variant] (_Each[type_like[E]] enum, **bot kwargs) -> instance + def self.[]: [E < Variant] (*type_like[E] elems, **bot kwargs) -> instance type index = _ToGodot[Int | Float] def []: (index key) -> E def get: (index key) -> E? - def []=: (index key, E value) -> E - def set: (index key, E value) -> E? + def []=: (index key, type_like[E] value) -> E + def set: (index key, type_like[E] value) -> E? include _Each[E] def each: () -> Enumerator[E, self] diff --git a/sig/variant.rbs b/sig/variant.rbs index 80ca833..c16bab9 100644 --- a/sig/variant.rbs +++ b/sig/variant.rbs @@ -1,8 +1,9 @@ module Godot interface _ToGodot[out G < Variant] def to_godot: () -> G end + type type_like[out T < Variant] = Kernel & _ToGodot[T] + type variant_like = type_like[Variant] type variant = Variant | bool? - type variant_like = Kernel & _ToGodot[Variant] class Variant include Godot VARIANT_TYPE: Integer