Skip to content

Commit

Permalink
CR
Browse files Browse the repository at this point in the history
  • Loading branch information
radeusgd committed May 12, 2023
1 parent 6e3ce38 commit 5627fa3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ handle_unmatched_type expected_types actual_value =
Error.throw (Type_Error.Error expected_types_str actual_value "range")
case m of
_ : Meta.Constructor ->
parent_type = m.parent_type
is_expected_constructor = expected_types.map Meta.meta . contains parent_type
declaring_type = m.declaring_type
is_expected_constructor = expected_types.map Meta.meta . contains declaring_type
if is_expected_constructor.not then return_type_error else
msg = "The constructor " + m.name + " is missing some arguments."
Error.throw (Illegal_Argument.Error msg)
Expand Down
22 changes: 11 additions & 11 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Meta.enso
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ type Type
## ADVANCED

Returns the fully qualified name of the type.
name : Text
name self =
qualified_name : Text
qualified_name self =
c = self.value
get_qualified_type_name c

## ADVANCED

Returns the short name of the type.
short_name : Text
short_name self =
name : Text
name self =
c = self.value
get_short_type_name c

Expand Down Expand Up @@ -121,10 +121,10 @@ type Constructor

## ADVANCED
Returns the type that this constructor is a part of.
parent_type : Type
parent_type self =
declaring_type : Type
declaring_type self =
c = self.value ...
Type.Value (get_constructor_parent_type c)
Type.Value (get_constructor_declaring_type c)

type Primitive
## PRIVATE
Expand Down Expand Up @@ -529,9 +529,9 @@ get_short_type_name : Any -> Text
get_short_type_name typ = @Builtin_Method "Meta.get_short_type_name"

## PRIVATE
Returns the type that this constructor is a child of.
Returns the type that this constructor is a part of.

Arguments:
- constructor: the constructor to get the parent type of.
get_constructor_parent_type : Any -> Any
get_constructor_parent_type constructor = @Builtin_Method "Meta.get_constructor_parent_type"
- constructor: the constructor to get the declaring type of.
get_constructor_declaring_type : Any -> Any
get_constructor_declaring_type constructor = @Builtin_Method "Meta.get_constructor_declaring_type"
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
import org.enso.interpreter.dsl.BuiltinMethod;
import org.enso.interpreter.runtime.callable.atom.AtomConstructor;
import org.enso.interpreter.runtime.data.Type;
import org.enso.interpreter.runtime.data.text.Text;

@BuiltinMethod(
type = "Meta",
name = "get_constructor_parent_type",
description = "Gets the name of a constructor.",
name = "get_constructor_declaring_type",
description = "Gets the type that declared this constructor.",
autoRegister = false)
public class GetConstructorParentTypeNode extends Node {
public class GetConstructorDeclaringTypeNode extends Node {
Type execute(AtomConstructor cons) {
return cons.getType();
}
Expand Down
6 changes: 3 additions & 3 deletions test/Tests/src/Semantic/Meta_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ spec =
Meta.is_atom typ . should_be_false
meta_typ = Meta.meta typ
meta_typ . should_be_a Meta.Type
meta_typ.short_name . should_equal "Boolean"
meta_typ.name . should_equal "Boolean"
cons = case meta_typ of
Meta.Type.Value _ -> meta_typ.constructors
_ -> Test.fail "Should be a Meta.Type.Value: " + meta_typ.to_text
Expand All @@ -223,7 +223,7 @@ spec =
Meta.is_atom typ . should_be_false
meta_typ = Meta.meta typ
meta_typ . should_be_a Meta.Type
meta_typ.short_name . should_equal "My_Type"
meta_typ.name . should_equal "My_Type"
cons = case meta_typ of
Meta.Type.Value _ -> meta_typ.constructors
_ -> Test.fail "Should be a Meta.Type.Value: " + meta_typ.to_text
Expand All @@ -232,7 +232,7 @@ spec =
cons.at 0 . should_be_a Meta.Constructor
cons . map (x -> x.name) . sort . should_equal [ "Value" ]
cons.each ctor->
ctor.parent_type . should_equal meta_typ
ctor.declaring_type . should_equal meta_typ

Test.specify "methods of MyType" <|
typ = My_Type
Expand Down

0 comments on commit 5627fa3

Please sign in to comment.