Enforce that abstract methods are implemented (#1785)

This adds a check that abstract members must be implemented.
If any members lack an implementation, an error is thrown describing
the missing members.

Co-authored-by: Dan Chao <dan.chao@apple.com>
This commit is contained in:
Jen Basch
2026-08-17 21:52:54 +00:00
committed by GitHub
co-authored by Dan Chao
parent 99c9f53063
commit 762db144ce
13 changed files with 182 additions and 31 deletions
@@ -0,0 +1,3 @@
abstract module Foo
abstract function bar(): Int
@@ -0,0 +1,8 @@
abstract class AbstractMethod {
abstract function foo(): Int
}
class MyClass extends AbstractMethod {
}
foo: MyClass
@@ -0,0 +1,9 @@
abstract class AbstractMethods {
abstract function foo(): Int
abstract function bar(): Int
}
class MyClass extends AbstractMethods {
}
foo: MyClass
@@ -0,0 +1 @@
extends "../../input-helper/classes/AbstractModule.pkl"
@@ -0,0 +1,10 @@
abstract class AbstractMethod {
abstract function foo(): Int
}
abstract class AbstractIntermediate extends AbstractMethod
class MyClass extends AbstractIntermediate {
}
foo: MyClass
@@ -0,0 +1,6 @@
–– Pkl Error ––
Class `abstractMethodNotImplemented1#MyClass` should either be declared `abstract`, or should implement method `foo()`.
x | class MyClass extends AbstractMethod {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at abstractMethodNotImplemented1 (file:///$snippetsDir/input/errors/abstractMethodNotImplemented1.pkl)
@@ -0,0 +1,8 @@
–– Pkl Error ––
Class `abstractMethodNotImplemented2#MyClass` should either be declared `abstract`, or should implement the following methods:
foo()
bar()
x | class MyClass extends AbstractMethods {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at abstractMethodNotImplemented2 (file:///$snippetsDir/input/errors/abstractMethodNotImplemented2.pkl)
@@ -0,0 +1,6 @@
–– Pkl Error ––
Class `abstractMethodNotImplemented3` should either be declared `abstract`, or should implement method `bar()`.
x | extends "../../input-helper/classes/AbstractModule.pkl"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at abstractMethodNotImplemented3 (file:///$snippetsDir/input/errors/abstractMethodNotImplemented3.pkl)
@@ -0,0 +1,6 @@
–– Pkl Error ––
Class `abstractMethodNotImplemented4#MyClass` should either be declared `abstract`, or should implement method `foo()`.
x | class MyClass extends AbstractIntermediate {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at abstractMethodNotImplemented4 (file:///$snippetsDir/input/errors/abstractMethodNotImplemented4.pkl)