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

Lint : Check reachable labels with required parameters #5318

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 15 additions & 10 deletions renpy/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ def check_unreachables(all_nodes):
def add_block(block):
next = block[0]
if next in unreachable:
to_check.add(next)
add_to_check(next)

def add_names(names):
for name in names:
Expand All @@ -924,7 +924,7 @@ def add_names(names):
continue

if node in unreachable:
to_check.add(node)
add_to_check(node)

# All nodes, outside of common.
all_nodes = [node for node in all_nodes if not common(node)]
Expand All @@ -939,6 +939,8 @@ def add_names(names):
# The worklist of reachable nodes that haven't been checked yet.
to_check = set()

add_to_check = to_check.add # type: ignore

for node in all_nodes:
if isinstance(node, (renpy.ast.EarlyPython, renpy.ast.Label)):
to_check.add(node)
Expand Down Expand Up @@ -975,6 +977,16 @@ def add_names(names):
elif isinstance(node, renpy.ast.RPY):
weakly_reachable.add(node)

def add_to_check(node):
to_check.add(node)
if (isinstance(node, renpy.ast.Label)
and node.parameters is not None
and any((p.default == p.empty)
and p.kind not in (p.VAR_POSITIONAL, p.VAR_KEYWORD)
for p in node.parameters.parameters.values())
):
report("Warning: label {} at {}:{} has required parameters but is reachable through script execution.".format(node.name, node.filename, node.linenumber))

while to_check:
node = to_check.pop() # type: Any
unreachable.remove(node)
Expand Down Expand Up @@ -1008,7 +1020,7 @@ def add_names(names):

next = node.next
if next in unreachable:
to_check.add(next)
add_to_check(next)

locations = sorted(set((node.filename, node.linenumber) for node in (unreachable - weakly_reachable)))
problems = [ (filename, linenumber, "") for filename, linenumber in locations ]
Expand All @@ -1017,13 +1029,6 @@ def add_names(names):

def check_orphan_translations(none_lang_identifiers, translation_identifiers):

def header():
print("")
print("")
print("Orphan Translations:")
print()


problems = [ ]

faulty = collections.defaultdict(list) # filename : [linenumbers]
Expand Down