godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.98k stars 21.16k forks source link

Different behaviours for the same problem: Values of the ternary conditional are not mutually compatible #53167

Open abelgutierrez99 opened 3 years ago

abelgutierrez99 commented 3 years ago

Godot version

3.3.3

System information

Windows 10

Issue description

This four cases for the same problem have different results (see comments)

extends Control

func _init():

    var value : int = 10

    var x : int = 1 if (value%2==0) else 0.5 # 1) Error : Values of the ternary conditional are not mutually compatible
    print(x) # 1

    var y : int = 1 if (10%2==0) else 0.5 # 2) No error arises and 'value=10'. The same error as in 1) should arise.
    print(y) # 1

    var z : float = 1 if (value%2==0) else 0.5 # same as 1)
    print(z) # 1

    var w : float = 1 if (10%2==0) else 0.5 # Same as 2)
    print(w) # 1

Steps to reproduce

Copy the code above and play the project.

Minimal reproduction project

Project.zip

Calinou commented 3 years ago

In the master branch (22b225395), I get no errors but only warnings:

image

1 is printed four times to the console.

vnen commented 1 year ago

This is not a problem in 4.0. It should be tested again in latest 3.x to see if it still happens.