Skip to content

Commit 19806e3

Browse files
committed
fixed "this" bugs
1 parent f96b4a0 commit 19806e3

5 files changed

Lines changed: 9 additions & 10 deletions

File tree

environment.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function get(Token $name)
4848
return $this->enclosing->get($name);
4949
}
5050

51-
throw new ParseError("Undef ".$name->literal);
51+
throw new RuntimeError($name, "Undefined variable '".$name->literal."'.");
5252
}
5353

5454
public function assign(Token $name, $value)
@@ -65,6 +65,6 @@ public function assign(Token $name, $value)
6565
return;
6666
}
6767

68-
throw new ParseError("Undef ".$name->literal);
68+
throw new RuntimeError($name, "Undefined variable '".$name->literal."'.");
6969
}
7070
}

interpreter.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,6 @@ private function setLocal(Expr $expr, $value)
7676
$this->locals[] = [$expr, $value];
7777
}
7878

79-
public function print(Expr $expr)
80-
{
81-
echo "lol\n";
82-
}
83-
8479
public function visitAssignExpr(AssignExpr $expr)
8580
{
8681
$value = $this->evaluate($expr->value);
@@ -219,7 +214,7 @@ public function visitSuperExpr(SuperExpr $expr)
219214

220215
public function visitThisExpr(ThisExpr $expr)
221216
{
222-
return lookUpVariable($expr->keyword, $expr);
217+
return $this->lookUpVariable($expr->keyword, $expr);
223218
}
224219

225220
public function visitUnaryExpr(UnaryExpr $expr)

resolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function visitClassStmt(ClassStmt $stmt)
114114
$this->currentClass = TYPE_CLASS;
115115

116116
$this->beginScope();
117-
$this->scopes[count($this->scopes)]["this"] = true;
117+
$this->scopes[count($this->scopes) - 1]["this"] = true;
118118

119119
foreach ($stmt->methods as $method)
120120
{

scanner.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ private function identifier()
193193
if (isset(self::$keywords[$str]))
194194
{
195195
$type = self::$keywords[$str];
196-
$str = null;
197196
}
198197

199198
$this->addToken($type, $str);

std/clock.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@ public function call(\Interpreter $interpreter, array $arguments)
1212
{
1313
return time();
1414
}
15+
16+
public function __tostring()
17+
{
18+
return 'Std\Clock';
19+
}
1520
}

0 commit comments

Comments
 (0)