                 value: value.resolve(resolver: resolver))
         
         case .this(let keyword):
+            if resolver.currentClass == .none {
+                Lox.error(keyword, "Cannot use 'this' outside of a class.")
+            }
+            
             let depth = resolver.resolveLocal(keyword)
             return .this(keyword: keyword, depth: depth)
         }

        case method
    }
    
    private var scopes: [[String: Bool]] = []
    private(set) var currentFunction: FunctionType = .none
    
    func begin() {
        scopes.append([:])

        case .class(let name, let methods):
            resolver.declare(name)
            resolver.define(name)
            let enclosingClass = resolver.currentClass
            resolver.currentClass = .class
            
            resolver.begin()
            resolver.defineThis()
