/
ResolverError.swift
52 lines (49 loc) · 1.96 KB
/
ResolverError.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// ResolverError.swift
// slox
//
// Created by Danielle Kefford on 3/3/24.
//
import Foundation
enum ResolverError: CustomStringConvertible, Equatable, LocalizedError {
case variableAccessedBeforeInitialization
case notAFunction
case variableAlreadyDefined(String)
case cannotReturnOutsideFunction
case cannotReferenceThisOutsideClass
case cannotReturnValueFromInitializer
case staticInitsNotAllowed
case classCannotInheritFromItself
case cannotReferenceSuperOutsideClass
case cannotReferenceSuperWithoutSubclassing
case cannotBreakOutsideLoop
case cannotContinueOutsideLoop
var description: String {
switch self {
case .variableAccessedBeforeInitialization:
return "Can't read local variable in its own initializer"
case .notAFunction:
return "Expected lambda as body of function declaration"
case .variableAlreadyDefined(let name):
return "Variable \(name) already defined in this scope"
case .cannotReturnOutsideFunction:
return "Cannot return from outside a function"
case .cannotReferenceThisOutsideClass:
return "Cannot use `this` from outside a class"
case .cannotReturnValueFromInitializer:
return "Cannot return value from an initializer"
case .staticInitsNotAllowed:
return "Cannot have class-level init function"
case .classCannotInheritFromItself:
return "Class cannot inherit from itself"
case .cannotReferenceSuperOutsideClass:
return "Cannot use `super` from outside a class"
case .cannotReferenceSuperWithoutSubclassing:
return "Cannot use `super` without subclassing"
case .cannotBreakOutsideLoop:
return "Can only `break` from inside a `while` or `for` loop"
case .cannotContinueOutsideLoop:
return "Can only `continue` from inside a `while` or `for` loop"
}
}
}