From 2d043e3a956e249791b9d81f54eb7305a2cb19de Mon Sep 17 00:00:00 2001 From: Jason Gwartz Date: Sun, 14 Apr 2024 12:55:04 +0100 Subject: [PATCH] Do not include function-type properties in codegen --- codegen/snippet-tests/input/04-withClass.pkl | 3 +++ codegen/src/internal/ClassGen.pkl | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/codegen/snippet-tests/input/04-withClass.pkl b/codegen/snippet-tests/input/04-withClass.pkl index c5390cb..06df605 100644 --- a/codegen/snippet-tests/input/04-withClass.pkl +++ b/codegen/snippet-tests/input/04-withClass.pkl @@ -1,6 +1,9 @@ class MyCustomClass { x: String y: Int + + // Function type properties should not be included in codegen + funcType: (String) -> (String) } value: MyCustomClass diff --git a/codegen/src/internal/ClassGen.pkl b/codegen/src/internal/ClassGen.pkl index 6268abd..73be5bb 100644 --- a/codegen/src/internal/ClassGen.pkl +++ b/codegen/src/internal/ClassGen.pkl @@ -120,8 +120,8 @@ function getFields( clazz.properties .filter((propName, prop: reflect.Property) -> let (superProp = superProperties.findOrNull((it) -> it.name == prop.name)) - // don't render hidden members - if (prop.modifiers.contains("hidden")) false + // don't render hidden members or functions + if (prop.modifiers.contains("hidden") || prop.type is reflect.FunctionType) false // Okay if there is no property override, or if the super property has the same type. else if (superProp == null || isSameType(superProp.type, prop.type) || isCompatibleType(superProp.type, prop.type)) true // Okay if the property is overridden but does not define a type, but don't render as its own field.