diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetConstructorFieldNamesNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetConstructorFieldNamesNode.java index 839a209747cc..0096e7b59fe7 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetConstructorFieldNamesNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetConstructorFieldNamesNode.java @@ -1,5 +1,7 @@ package org.enso.interpreter.node.expression.builtin.meta; +import com.oracle.truffle.api.dsl.Fallback; +import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.nodes.Node; import org.enso.interpreter.dsl.BuiltinMethod; import org.enso.interpreter.runtime.callable.argument.ArgumentDefinition; @@ -12,8 +14,15 @@ name = "get_constructor_fields", description = "Gets the field names of a constructor.", autoRegister = false) -public class GetConstructorFieldNamesNode extends Node { - Array execute(AtomConstructor atom_constructor) { +public abstract class GetConstructorFieldNamesNode extends Node { + static GetConstructorFieldNamesNode build() { + return GetConstructorFieldNamesNodeGen.create(); + } + + abstract Array execute(Object obj); + + @Specialization + final Array executeAtomConstructor(AtomConstructor atom_constructor) { ArgumentDefinition[] fields = atom_constructor.getFields(); Object[] result = new Object[fields.length]; for (int i = 0; i < fields.length; i++) { @@ -21,4 +30,9 @@ Array execute(AtomConstructor atom_constructor) { } return new Array(result); } + + @Fallback + final Array executeAny(Object any) { + return Array.empty(); + } } diff --git a/test/Tests/src/Semantic/Meta_Spec.enso b/test/Tests/src/Semantic/Meta_Spec.enso index c07abc386a8e..3d2ca4767064 100644 --- a/test/Tests/src/Semantic/Meta_Spec.enso +++ b/test/Tests/src/Semantic/Meta_Spec.enso @@ -171,6 +171,18 @@ spec = e_tpe . should_equal_type IOException e_tpe . should_not_equal_type JException + Test.specify "fields of a Type" <| + typ = Boolean + + Meta.is_atom typ . should_be_true + meta_typ = Meta.meta typ + meta_typ . should_be_a Meta.Atom + fields = case meta_typ of + Meta.Atom.Value _ -> meta_typ.constructor.fields + _ -> Test.fail "Should be a Meta.Atom.Value: " + meta_typ.to_text + + fields . should_equal [] + Test.specify "should correctly handle Java values" <| java_meta = Meta.meta Random.new java_meta . should_be_a Meta.Polyglot.Value