Skip to content

Commit

Permalink
Fixed an environment related issue that causes class inheritance not …
Browse files Browse the repository at this point in the history
…function
  • Loading branch information
theSalted committed Jul 22, 2024
1 parent 182f3a3 commit 9896b1e
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Sources/Lox/Interpreter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,20 @@ public final class Interpreter: StatementVisitor, ExpressionVisitor {

// Class assembly
let `class` = LoxClass(stmt.name.lexeme, superclass: superclass, methods: methods)
do { try environment.assign(name: stmt.name, value: `class`) }
do {
try environment.assign(name: stmt.name, value: `class`)

if superclass != nil {
guard let enclosing = environment.enclosing else {
throw InterpreterError.runtime( /*This should never happen*/
message: "Something went wrong while declaring your class with proper environment",
onLine: stmt.name.line,
locationDescription: nil)
}

environment = enclosing
}
}
catch { return .failure(
error as? InterpreterError ??
InterpreterError.runtime( /*This should never happen*/
Expand Down

0 comments on commit 9896b1e

Please sign in to comment.