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

UNSAFE_METHOD_ACCESS warning emitted inside type guard #86376

Closed
voithos opened this issue Dec 21, 2023 · 1 comment
Closed

UNSAFE_METHOD_ACCESS warning emitted inside type guard #86376

voithos opened this issue Dec 21, 2023 · 1 comment

Comments

@voithos
Copy link
Contributor

voithos commented Dec 21, 2023

Tested versions

4.2.1.stable.official

System information

Godot v4.2.1.stable - Windows 10.0.22621 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 4090 (NVIDIA; 31.0.15.2849) - 13th Gen Intel(R) Core(TM) i9-13900K (32 Threads)

Issue description

An UNSAFE_METHOD_ACCESS warning is emitted when I would've expected the type system to automatically type-narrow inside of a type guard, something like:

if node is SomeType:
  # `node` should be a `SomeType` in this block.
  node.some_type_method()

Steps to reproduce

  • Enable 'UNSAFE_METHOD_ACCESS' warnings in project settings
  • Add this function anywhere and play the game:
func test(node: Node2D) -> void:
	if node is Area2D:
		node.get_overlapping_areas()
  • The following warning is emitted:
W 0:00:00:0707   The method "get_overlapping_areas()" is not present on the inferred type "Node2D" (but may be present on a subtype).

This can be worked around by explicitly type casting after performing the check:

func test(node: Node2D) -> void:
	if node is Area2D:
		(node as Area2D).get_overlapping_areas()

Minimal reproduction project (MRP)

N/A

@dalexeev
Copy link
Member

This is not a bug. Feature requests should be opened in the godot-proposals repository, this tracker is only for bugs. See these proposals:

Thanks for the contribution nonetheless!

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

2 participants