                         }
                     }
                     if runtime.returnType != .none {
-                        let callStack = callStack.appending(function.steps.count)
-                        guard function.hasReturnStep else { throw DecodeError(cause: .returnMissing, stack: callStack) }
-                        try check(function.returnStep, with: runtime.returnType, function: function, stack: stack, callStack: callStack)
-                    } else if function.hasReturnStep { throw DecodeError(cause: .returnMismatch, stack: callStack) }
-                    releaseResults[callStack] = Dictionary(grouping: runtime.releaseResult.enumerated()) { $0.element }.mapValues { $0.map { $0.offset } }
+                        let callStack = callStack.appending(runtime.function.steps.count)
+                        guard runtime.function.hasReturnStep else { throw DecodeError(cause: .returnMissing, stack: callStack) }
+                        try check(runtime.function.returnStep, with: runtime.returnType, stack: stack, codePath: codePath, callStack: callStack)
+                    } else if runtime.function.hasReturnStep { throw DecodeError(cause: .returnMismatch, stack: callStack) }
+                    releaseResults[codePath] = Dictionary(grouping: runtime.releaseResult.enumerated()) { $0.element }.mapValues { $0.map { $0.offset } }
                 }
                 
                 func typecheck(function: Function, arguments: [DeclarationType], returnType: DeclarationType) throws {
-                    try typecheck(function: function, stack: [TypecheckRuntime(arguments: arguments, returnType: returnType, count: function.steps.count)], callStack: [])
+                    try typecheck(stack: [TypecheckRuntime(function: function, arguments: arguments, returnType: returnType)], codePath: [], callStack: [])
                 }
 
                 private func value(_ a: Function.A, in stack: [Runtime<Any>]) -> Any {

            case .function(let functionType):
                output.append("            case .\(name)(let a):\n")
                for (i, type) in ([name] + functionType.argumentTypes).enumerated() {
                    output.append("                try check(a.o\(i + 1), with: .\(type)Type, function: function, stack: stack, callStack: callStack)\n")
                }
                if let type = functionType.returnType {
                    output.append("                runtime.results[i] = .\(type)Type\n")

                    return false
                }

                private func check(_ a: Function.A, with type: DeclarationType, stack: [TypecheckRuntime], codePath: IndexPath, callStack: IndexPath) throws {
                    if a.step >= 0 {
                        guard a.level < stack.count else { throw DecodeError(cause: .stepMissing, stack: callStack) }
                        let runtime = stack[Int(a.level)]
