Skip to content

Fix false positive "Unreachable code" warning for loops

Rafał Mikrut requested to merge github/fork/yamgent/unreachable into master

Created by: yamgent

  1. The first commit is to fix #35775. It will fix erroneous reports in these two cases:
func a():
	var arr = []
	for i in arr:
		return i
	# can be reached, but buggy analysis says cannot
	return -1

func b():
	var should_loop = false
	while should_loop:
		return 1
	# can be reached, but buggy analysis says cannot
	return 0
  1. The second commit exist, because I notice that the intention of the has_return variable has clearly evolved as new fixes are pushed (see previous problems with erroneous "unreachable code" such as #25955 (closed) and #30458 (closed)). I feel that the name has_return is now less appropriate as a result. I propose the new name to be has_unconditional_return, for blocks that has an "unavoidable" return statement. Name feels a bit long though, so I am open to any suggestions to improve the name.

Merge request reports

Loading