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

Fix: Wrong unreachable warning after returning from match's wildcard pattern #25955 #26097

Merged
merged 1 commit into from Apr 1, 2019
Merged

Fix: Wrong unreachable warning after returning from match's wildcard pattern #25955 #26097

merged 1 commit into from Apr 1, 2019

Conversation

danielspaniol
Copy link

Fixes #25955

Problem

The parser only checked if the catch-all branch has a return in order to determine if the entire match block has a return.

This code block was assumed to always return.

match value:
    "test":
        print("test")
    _:
        return

This in turn means that every code following was regarded unreachable.

Solution

Every match is assumed to have a return, unless we find one branch to not return.

Before the parser only checked if the catch-all branch has a return in
order to determine if the entire match block has a return.

This code block was assumed to always return.

    match value:
        "test":
            print("test")
        _:
            return

Now as soon as one of the branches has no return, the entire match block
is marked to not have a return.
Copy link
Contributor

@bojidar-bg bojidar-bg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vnen
Copy link
Member

vnen commented Mar 17, 2019

Looks good to me.

I noticed that the email you used to commit is not attached to your GitHub account. It does not prevent merging, but the contribution won't be associated with your GH account, so you won't be labeled as contributor in the GH interface. If you want to fix that you can either add the email of the commit to your account or change the email in the commit by amending it.

@akien-mga akien-mga merged commit 4ec384f into godotengine:master Apr 1, 2019
@akien-mga
Copy link
Member

Thanks!

@akien-mga
Copy link
Member

Cherry-picked for 3.1.1.

@aburg
Copy link

aburg commented Jul 9, 2019

the "unreachable code" warning still gets throws for the following script (v3.1.1.stable.official):

extends Node2D

func _ready():
	var selector = 0
	match selector:
		1:
			return
	
	print("we reached the unreachable")

warning output:

W 0:00:00:0586   Unreachable code (statement after return) in function '_ready()'.
  <Source>       Node2D.gd:9

output:

** Debug Process Started **
OpenGL ES 3.0 Renderer: GeForce GTS 450/PCIe/SSE2
we reached the unreachable

can you reopen this issue? or should i create a new one? o.0

@akien-mga
Copy link
Member

Please open a new issue.

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

Successfully merging this pull request may close these issues.

Wrong unreachable warning after returning from match's wildcard pattern
6 participants