mirror of
https://github.com/enso-org/enso.git
synced 2024-11-26 08:52:58 +03:00
Meta.get_constructor_fields works for Type (#5869)
Fixes #5805 by returning `[]` as list of fields of `Type`. # Important Notes `Type` is recognized as `Meta.is_atom` since #3671. However `Type` isn't an `Atom` internally. We have to provide special handling for it where needed.
This commit is contained in:
parent
952beba8d1
commit
888307f03f
@ -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 @@ import org.enso.interpreter.runtime.data.text.Text;
|
||||
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 @@ public class GetConstructorFieldNamesNode extends Node {
|
||||
}
|
||||
return new Array(result);
|
||||
}
|
||||
|
||||
@Fallback
|
||||
final Array executeAny(Object any) {
|
||||
return Array.empty();
|
||||
}
|
||||
}
|
||||
|
@ -199,6 +199,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
|
||||
|
Loading…
Reference in New Issue
Block a user