feat: prevent subclassing of built-in types with runtime error in class creation
Add a check in the interpreter's class creation path that detects when a user-defined class attempts to inherit from any of the seven built-in types (Class, Fiber, Fn, List, Map, Range, String). When such an inheritance is detected, a runtime error is raised with a descriptive message indicating the class name and that it may not subclass a built-in. This implements the restriction discussed in issue #70. Also adds test files for each built-in type to verify the runtime error is correctly triggered, and includes a commented-out test for closure subclassing that currently causes a segfault.
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
class SubClass is Class {} // expect runtime error: Class 'SubClass' may not subclass a built-in
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
var f = null
|
||||
|
||||
{
|
||||
var a = "a"
|
||||
f = new Fn {
|
||||
IO.print(a)
|
||||
}
|
||||
}
|
||||
//@FIXME: repair the segfault create a propper test for the subclassing
|
||||
|
||||
//var closureSegfault = f
|
||||
//class SubClosureSegfault is closureSegfault {}
|
||||
|
||||
//var closureOk = f.call
|
||||
//class SubClosureOk is closureOk {}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
class SubFiber is Fiber {} // expect runtime error: Class 'SubFiber' may not subclass a built-in
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
class SubFn is Fn {} // expect runtime error: Class 'SubFn' may not subclass a built-in
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
class SubList is List {} // expect runtime error: Class 'SubList' may not subclass a built-in
|
||||
@@ -0,0 +1,2 @@
|
||||
class SubMap is Map {} // expect runtime error: Class 'SubMap' may not subclass a built-in
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
class SubRange is Range {} // expect runtime error: Class 'SubRange' may not subclass a built-in
|
||||
@@ -0,0 +1,2 @@
|
||||
class SubString is String {} // expect runtime error: Class 'SubString' may not subclass a built-in
|
||||
|
||||
Reference in New Issue
Block a user