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

text_bubble.gd (and subsystem_portraits.gd) contain Inference on Variant warning treated as error, prevents customizing script in project code #2248

Closed
hsandt opened this issue May 22, 2024 · 1 comment · Fixed by #2253
Labels
Bug 🐞 Something isn't working

Comments

@hsandt
Copy link

hsandt commented May 22, 2024

The problem

Describe the bug
I wanted to customize text_bubble.gd and therefore copied it to some local custom_text_bubble.gd (the same way as Dialogic offers a built-in way to customize Layers, creating custom_text_bubble_layer.tscn and text_bubble_layer.gd, but going further and also copying custom_text_bubble.tscn and its script).

However, the code revealed to trigger some code warning, which by default is treated as an error:

func _process(delta:float) -> void:
	# ...
	var dist_x := abs(base_position.x - center.x) # Line 54
	var dist_y := abs(base_position.y - center.y) # Line 55

Line 54:The variable type is being inferred from a Variant value, so it will be typed as Variant. (Warning treated as error.)

and same for Line 55

They can be disabled by unchecking project setting:

debug/gdscript/warnings/inference_on_variant (Inference on Variant)

however it seems cleaner to handle these properly in code. In this case, using absf instead of abs (in fact I had exactly the same issue on my own addon so it helped me find where the issue was).

Add-on code is not parsed by default, so this only appears when duplicating code to local project sub-folder for customization, or when disabling Project Settings > debug/gdscript/warnings/exclude_addons, in which case you get even another warning:

res://addons/dialogic/Modules/Character/subsystem_portraits.gd
var test := dialogic.Expressions.execute_string(portrait) # Also Inference on Variant

but this one is really a variant, so there is nothing clever to do except replacing := with = I suppose.

To Reproduce
Steps to reproduce the behavior:

  1. Disable Project Settings > debug/gdscript/warnings/exclude_addons OR duplicate text_bubble.gd and subsystem_portraits.gd to project sub-folder
  2. Make sure that debug/gdscript/warnings/inference_on_variant is set to Error
  3. Wait for parser error to appear, or Play to force parse
  4. See warnings treated as errors

Expected behavior
No code warnings (even less ones treated as errors by default).

Screenshots

image

System (please complete the following information):

  • OS: Linux Ubuntu 22.04
  • Godot Version: v4.2.1.stable.official [b09f793f5]
  • Dialogic Version: main commit a9c56aa (2024-05-05)

Solutions

Possible fixes

Use precise type methods absf in text_bubble.gd, and don't use static typing at all in subsystem_portraits.gd for the test variable, to avoid all warnings.

hsandt added a commit to hsandt/lospec-jam-2-scaled-down-adventures that referenced this issue May 22, 2024
@Jowan-Spooner
Copy link
Collaborator

Appreciate the report. This is absolutely something we can and should do!

Btw, while I really like that you take a lot of time to report and investigate these issues, feel free to keep the description a bit shorter for simple things like this. Especially if you are pretty certain what causes the bug.
E.g. in this case it would have been enough for me to say something like this:

When making the textbubble layer custom, these lines give an error (with default error/warning settings):
...
*Error Message*
It can easily be fixed by using `absf()` instead of `abs()`

Also the type inference in SubsystemPortraits line x fails and should be explicit.
...

Just to give an example. Don't get me wrong, long issues are good, especially when people don't know what the problem is, but for things like this, feel free to condense it and save yourself some time ;)

@Jowan-Spooner Jowan-Spooner added the Bug 🐞 Something isn't working label May 23, 2024
Jowan-Spooner added a commit to Jowan-Spooner/dialogic that referenced this issue May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐞 Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants