Skip to content

Commit

Permalink
Do not allow inheriting built-in classes Num, Bool and Null (#831)
Browse files Browse the repository at this point in the history
* Do not allow inheriting `Num`, `Bool` and `Null`. fixes #830
  • Loading branch information
ChayimFriedman2 committed Oct 26, 2020
1 parent ad4e039 commit 44d6d20
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/vm/wren_vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,10 @@ static Value validateSuperclass(WrenVM* vm, Value name, Value superclassValue,
superclass == vm->listClass ||
superclass == vm->mapClass ||
superclass == vm->rangeClass ||
superclass == vm->stringClass)
superclass == vm->stringClass ||
superclass == vm->boolClass ||
superclass == vm->nullClass ||
superclass == vm->numClass)
{
return wrenStringFormat(vm,
"Class '@' cannot inherit from built-in class '@'.",
Expand Down
1 change: 1 addition & 0 deletions test/language/inheritance/inherit_from_bool.wren
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class Subclass is Bool {} // expect runtime error: Class 'Subclass' cannot inherit from built-in class 'Bool'.
1 change: 1 addition & 0 deletions test/language/inheritance/inherit_from_null_class.wren
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class Subclass is Null {} // expect runtime error: Class 'Subclass' cannot inherit from built-in class 'Null'.
1 change: 1 addition & 0 deletions test/language/inheritance/inherit_from_num.wren
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class Subclass is Num {} // expect runtime error: Class 'Subclass' cannot inherit from built-in class 'Num'.

0 comments on commit 44d6d20

Please sign in to comment.