How can I fix this "Not all code paths return a value" issue

Question

I am currently trying to make a drunkard's walk algorithm in godot 4.6. Currently, I have an error on line 11 that says "Not all code paths return a value.

I am following a tutorial and I have copied the code almost word for word (at least from what I can tell) Here is the tutorial: Drunkard’s Walk and Natural Cave Generation | How to Make Procedural Dungeons in GODOT

This is the code:

class_name DrunkGuy extends Node2D

@export var spawn_count : int = 1
@export var minimum_walk : int = 100

var drunkards: Array[Vector2i] = []
var step_count : int = 0

#creates the initial dungeon as an array filled with arrays
func generate (size: Vector2i) -> Array[Array] :
	var map : Array[Array] = []
	for i in size.x:
		map.push_back([])
		for j in size.y:
			map[i].push_back([1])
			
	step_count = 0
	
	for count in spawn_count:
		drunkards.push_back(spawn(size))
		
	#carves out spwan point of each drunkard
	for drunkard in drunkards:
		map[drunkard.x][drunkard.y] = 0
		
	for step in minimum_walk:
		#until minimum steps is reached, step in random direction and carve out final position
		crawl(size, map)

#when called, each drunkard will take 1 step in random direction
func crawl(size : Vector2i, map: Array[Array]):
	var updated_drunkard : Array[Vector2i] = []
	var directions : Array[Vector2i] = [] 
	
	for drunkard in drunkards:
		
		if drunkard.x > 0: # if drunkard is to the left side
			directions.push_back(Vector2i(1, 0))
			
		if drunkard.x < size.x - 1: # if drunkard is to the right side
			directions.push_back(Vector2i(-1, 0))
			
		if drunkard.y > 0: # if drunkard is at the top
			directions.push_back(Vector2i(0, -1))
		else:
			directions.push_back(Vector2i(0,0))
		
		var walk_direction : Vector2i = directions.pick_random() # moves left, right, and up, respectively
		updated_drunkard.push_back((drunkard as Vector2i) + walk_direction)
		map[drunkard.x][drunkard.y] = 0 #carves out the drunkard's position
		
	drunkards = updated_drunkard
		
#spawn a drunkard in a random spot in the grid
func spawn(size: Vector2i):
	#positions drunkard within 0 and the size of the cave (size), and returns position
	var drunkard_position : Vector2i = Vector2i(randi_range(0, size.x), 0)
	return drunkard_position

Does anyone know how to fix this? If you do, please let me know.

Your function

func generate (size: Vector2i) -> Array[Array] :

tells that it returns Array[Array] but it doesn’t return anything. I didn’t watch the 47 minute video, but I would guess that the function should the return map, which seems to the be type of Array[Array].

So return generated mapat the end of the function:

return map

In hindsight, that does make a lot of sense

Thanks for the advice!