Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using bool() on a float emits a warning if done on a typed variable #64649

Open
MrPaiZi opened this issue Aug 20, 2022 · 2 comments
Open

Using bool() on a float emits a warning if done on a typed variable #64649

MrPaiZi opened this issue Aug 20, 2022 · 2 comments

Comments

@MrPaiZi
Copy link

MrPaiZi commented Aug 20, 2022

Godot version

v3.5.stable.official [991bb6a]

System information

Windows 10

Issue description

When I use bool(), I pass in a float, and although it works fine, I get an unexpected warning:

W 0:00:00.637   Narrowing conversion (float is converted to int and loses precision).
  <C++ Error>   NARROWING_CONVERSION
  <Source>      PlayerState.gd:15

image

Steps to reproduce

You must pass a static typing float variable to run this method. Check minimal reproduction project.

Minimal reproduction project

var f: float = 0.1
print(bool(f)) # warning
var f := 0.1
print(bool(f)) # warning
var f = 0.1
print(bool(f)) # no warning
@Calinou Calinou changed the title Unexpected warnings of bool() bool() on a float emits a warning if done on a typed variable Aug 20, 2022
@Calinou Calinou changed the title bool() on a float emits a warning if done on a typed variable Using bool() on a float emits a warning if done on a typed variable Aug 20, 2022
@Calinou Calinou added this to the 3.x milestone Aug 20, 2022
@Kingofd
Copy link

Kingofd commented Aug 26, 2022

Tested on Manjaro 5.19.0.-2, same problem.
I would take care of it but what is to be done about it?
Suppress error in C++ where it is thrown? Throw it regardless of typed or non-typed variable?

@Mickeon
Copy link
Contributor

Mickeon commented Sep 1, 2022

May be caused by this but I do not currently understand how the parser works, myself:

if (arg_type.kind == DataType::BUILTIN && arg_type.builtin_type == Variant::INT && par_types[i].kind == DataType::BUILTIN && par_types[i].builtin_type == Variant::REAL) {
_add_warning(GDScriptWarning::NARROWING_CONVERSION, p_call->line, Variant::get_type_name(tn->vtype));
}

This error does not occur in latest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants