godot icon indicating copy to clipboard operation
godot copied to clipboard

Restore numeric from String constructors

Open KoBeWi opened this issue 3 years ago • 5 comments

Closes #44407

KoBeWi avatar Jul 07 '22 11:07 KoBeWi

Lots of CI build errors along those lines:

core/variant/variant_construct.h: In static member function 'static void VariantConstructorFromString<T>::ptr_construct(void*, const void**) [with T = long int]':
core/variant/variant_construct.h:258:11: error: 'dst_var' may be used uninitialized in this function [-Werror=maybe-uninitialized]
  258 |   Variant type_test = Variant(dst_var);
      |           ^~~~~~~~~
core/variant/variant_construct.h: In static member function 'static void VariantConstructorFromString<T>::ptr_construct(void*, const void**) [with T = double]':
core/variant/variant_construct.h:258:11: error: 'dst_var' may be used uninitialized in this function [-Werror=maybe-uninitialized]
  258 |   Variant type_test = Variant(dst_var);
      |           ^~~~~~~~~

akien-mga avatar Jul 07 '22 15:07 akien-mga

I guess GetTypeInfo<T>::VARIANT_TYPE can be used instead of dummy Variants.

cdemirer avatar Jul 09 '22 16:07 cdemirer

I am not happy with this kind of automatic cast, as it an be quite prone to errors. We discussed with @vnen at that point in time and believed it would be better you use the str() function instead in GDScript.

reduz avatar Aug 08 '22 10:08 reduz

But the PR is about int("string"). It no longer works in 4.0. I don't know how it works internally; if it causes implicit conversions then I agree it's bad :/

KoBeWi avatar Aug 08 '22 10:08 KoBeWi

I checked and this

var a: int
a = "123"

does not work, so I guess it's fine? 🤔

KoBeWi avatar Sep 19 '22 12:09 KoBeWi

To me this looks completely fine. Reduz may have gotten confused. I tried myself, and no implicit conversion is done. There may be other circumstances where it is, however?

Mickeon avatar Nov 15 '22 19:11 Mickeon

Thanks!

akien-mga avatar Nov 15 '22 21:11 akien-mga