Skip to content

Add warnings for shadowed @GDScriptand @GlobalScope functions#106987

Open
EdwardChanCH wants to merge 1 commit intogodotengine:masterfrom
EdwardChanCH:tooltip_global_method_hides_local
Open

Add warnings for shadowed @GDScriptand @GlobalScope functions#106987
EdwardChanCH wants to merge 1 commit intogodotengine:masterfrom
EdwardChanCH:tooltip_global_method_hides_local

Conversation

@EdwardChanCH
Copy link
Copy Markdown
Contributor

@EdwardChanCH EdwardChanCH commented May 31, 2025

Closes: godotengine/godot-proposals#14425

Related: #106984

Note: Some previous code has been split into #117308 to keep this PR manageable.

Any help is appreciated!

@EdwardChanCH EdwardChanCH changed the title Fixed GDScript editor showing local method when global method is exec… Fix GDScript tooltip showing overrided global methods with warnings May 31, 2025
@EdwardChanCH EdwardChanCH changed the title Fix GDScript tooltip showing overrided global methods with warnings Fix GDScript tooltip showing global method overrides with warnings May 31, 2025
@AThousandShips AThousandShips added bug topic:gdscript cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release labels May 31, 2025
@AThousandShips AThousandShips added this to the 4.5 milestone May 31, 2025
@EdwardChanCH
Copy link
Copy Markdown
Contributor Author

EdwardChanCH commented Jun 6, 2025

Discovered more bugs:

  • When hovering over the middle of a named lambda name, the tooltip is shown only for @GDScript functions.
  • When hovering over the left edge of a named lambda name, the tooltip is shown for native, @GDScript, @GlobalScope, and local functions.
  • When hovering over the middle of a function name, the tooltip is shown only for native and @GDScript functions.
  • When hovering over the left edge of a function name, the tooltip is shown only for native and @GDScript functions.

Edit: Fixed.

@EdwardChanCH EdwardChanCH force-pushed the tooltip_global_method_hides_local branch from aa1a41a to d8801db Compare June 6, 2025 18:32
@EdwardChanCH EdwardChanCH force-pushed the tooltip_global_method_hides_local branch 2 times, most recently from 431b30e to 93ed582 Compare June 15, 2025 00:22
@EdwardChanCH EdwardChanCH marked this pull request as ready for review June 15, 2025 00:56
@EdwardChanCH EdwardChanCH requested review from a team as code owners June 15, 2025 00:56
@Repiteo Repiteo added the cherrypick:4.5 Considered for cherry-picking into a future 4.5.x release label Sep 18, 2025
@Repiteo Repiteo modified the milestones: 4.5, 4.x Sep 18, 2025
@EdwardChanCH EdwardChanCH changed the title Fix GDScript tooltip showing global method overrides with warnings Add warnings for global function override for @GDScript and @GlobalScope Mar 11, 2026
@EdwardChanCH EdwardChanCH requested review from a team as code owners March 11, 2026 04:31
@EdwardChanCH EdwardChanCH requested a review from a team as a code owner March 11, 2026 04:31
@EdwardChanCH EdwardChanCH force-pushed the tooltip_global_method_hides_local branch 2 times, most recently from 2384e63 to 4e01b99 Compare March 11, 2026 04:34
@Nintorch Nintorch removed request for a team March 11, 2026 04:35
@EdwardChanCH
Copy link
Copy Markdown
Contributor Author

Thanks for removing the 29 extra team reviews, not sure what happened there...

Comment thread modules/gdscript/tests/scripts/analyzer/warnings/overriding_native_method.out Outdated
Comment thread modules/gdscript/gdscript_warning.h Outdated
@EdwardChanCH
Copy link
Copy Markdown
Contributor Author

EdwardChanCH commented Mar 12, 2026

Below is a full summary of what this PR fixed:

@warning_ignore_start("unused_parameter", "unused_variable", "unused_signal", "untyped_declaration", "inferred_declaration")

class_name ceil # Missing warning. <-- Too complex to fix in this PR.
extends Node

class floor extends Node: # Missing warning. <-- Fixed! Now warns (SHADOWED_GLOBAL_IDENTIFIER)
	func f() -> void:
		pass

var sin = 111 # (SHADOWED_GLOBAL_IDENTIFIER)
const cos = 222 # (SHADOWED_GLOBAL_IDENTIFIER)

# Named enum identifier do not shadow anything, because it can only be accessed as NamedEnum.EnumIdentifier.

enum max { # Missing warning. <-- Fixed! Now warns (SHADOWED_GLOBAL_IDENTIFIER)
	min = 333 # No warning as expected.
}

enum {
	clamp,       # Missing warning. <-- Fixed! Now warns (SHADOWED_GLOBAL_IDENTIFIER)
	clampi = 444 # Missing warning. <-- Fixed! Now warns (SHADOWED_GLOBAL_IDENTIFIER)
}

# Note: Signal parameter do not shadow anything.

signal sqrt # Missing warning. <-- Fixed! Now warns (SHADOWED_GLOBAL_IDENTIFIER)

signal s(pow) # No warning as expected.

func get(_property: StringName) -> Variant: # (NATIVE_METHOD_OVERRIDE)
	return 100

func char(code :int): # Missing warning. <-- Fixed! Now warns (SHADOWED_GLOBAL_IDENTIFIER)
	return 200

func log(x: float): # Missing warning. <-- Fixed! Now warns (SHADOWED_GLOBAL_IDENTIFIER)
	return 300

func unique(log: float): # (SHADOWED_GLOBAL_IDENTIFIER)
	return 400

func unique2(...log): # (SHADOWED_GLOBAL_IDENTIFIER)
	return 500

# Note: Named lambdas do not override anything.

# No warning as expected.
var named_lambda_1 = func get():
	return null

# No warning as expected.
var named_lambda_2 = func char():
	return null

# No warning as expected.
var named_lambda_3 = func log():
	return null

var named_lambda_4 = func unique():
	return null

func _ready() -> void:
	var sinh = 1 # (SHADOWED_GLOBAL_IDENTIFIER)
	
	for char in []: # (SHADOWED_GLOBAL_IDENTIFIER)
		pass
	
	var k = 1
	match k:
		var abs: # (SHADOWED_GLOBAL_IDENTIFIER)
			pass
	
	# The new warnings are consistent with how GDScript is parsed.
	print(sin) # Prints 111
	print(cos) # Prints 222
	print(max) # Prints { "min": 333 }
	print(min) # Prints @GlobalScope::min
	print(max.min) # Prints 333
	print(clamp) # Prints 0
	print(clampi) # Prints 444
	print(ceil) # Prints (res://main.gd):<GDScript#-9223372002226600493>
	print(floor) # Prints ():<GDScript#-9223372002042051115>
	print(sqrt) # Prints Node(main.gd)::[signal]sqrt
	print(s) # Prints Node(main.gd)::[signal]s

@EdwardChanCH
Copy link
Copy Markdown
Contributor Author

EdwardChanCH commented Mar 12, 2026

class_name ceil # Missing warning. <-- Too complex to fix in this PR.

Fixing this (in the future) will require changing GDScriptAnalyzer::is_shadowing(), since it detects the current script's class_name as a global identifier.

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

Labels

bug cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release cherrypick:4.5 Considered for cherry-picking into a future 4.5.x release topic:gdscript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add warnings for shadowed @GDScript and @GlobalScope functions

4 participants