mirror of
https://github.com/enso-org/enso.git
synced 2024-12-23 13:02:07 +03:00
Fix issue where constructor was becoming a value. Fixes to_json. (#3955)
If a constructor is fully specified the Meta constructor was becoming the atom in a few places. This broke to_json and hence viz.
This commit is contained in:
parent
0855b74875
commit
8f30fcf376
@ -83,8 +83,8 @@ type Any
|
||||
that_meta = Meta.meta that
|
||||
case Pair.new self_meta that_meta of
|
||||
Pair.Value (Meta.Atom.Value _) (Meta.Atom.Value _) ->
|
||||
c_1 = self_meta.constructor ...
|
||||
c_2 = that_meta.constructor ...
|
||||
c_1 = self_meta.constructor.value ...
|
||||
c_2 = that_meta.constructor.value ...
|
||||
if Meta.is_same_object c_1 c_2 . not then False else
|
||||
f_1 = self_meta.fields
|
||||
f_2 = that_meta.fields
|
||||
|
@ -29,7 +29,7 @@ Any.to_json self =
|
||||
m = Meta.meta self
|
||||
case m of
|
||||
_ : Meta.Atom ->
|
||||
cons = Meta.Constructor.Value m.constructor
|
||||
cons = m.constructor
|
||||
fs = m.fields
|
||||
fnames = cons.fields
|
||||
json_fs = 0.up_to fnames.length . fold Map.empty m-> i->
|
||||
|
@ -314,7 +314,7 @@ into_helper fmt json = case fmt of
|
||||
case m of
|
||||
_ : Meta.Atom -> case json of
|
||||
Json.Object json_fields ->
|
||||
cons = Meta.Constructor.Value m.constructor
|
||||
cons = m.constructor
|
||||
field_names = cons.fields
|
||||
field_formats = m.fields
|
||||
field_values = field_names.zip field_formats n-> inner_format->
|
||||
|
@ -17,14 +17,14 @@ import project.Polyglot.Polyglot as Base_Polyglot
|
||||
|
||||
from project.Data.Boolean import Boolean, True, False
|
||||
|
||||
## UNSTABLE
|
||||
ADVANCED
|
||||
|
||||
An Atom meta-representation.
|
||||
|
||||
Arguments:
|
||||
- value: The value of the atom in the meta representation.
|
||||
type Atom
|
||||
## UNSTABLE
|
||||
ADVANCED
|
||||
|
||||
An Atom meta-representation.
|
||||
|
||||
Arguments:
|
||||
- value: The value of the atom in the meta representation.
|
||||
Value value
|
||||
|
||||
## UNSTABLE
|
||||
@ -39,16 +39,18 @@ type Atom
|
||||
|
||||
Returns a constructor value of the given atom.
|
||||
constructor : Constructor
|
||||
constructor self = get_atom_constructor self.value ...
|
||||
constructor self =
|
||||
java_constructor = get_atom_constructor self.value ...
|
||||
Meta.Constructor.Value java_constructor
|
||||
|
||||
## UNSTABLE
|
||||
ADVANCED
|
||||
|
||||
A constructor meta-representation.
|
||||
|
||||
Arguments:
|
||||
- value: The value of the constructor in the meta representation.
|
||||
type Constructor
|
||||
## UNSTABLE
|
||||
ADVANCED
|
||||
|
||||
A constructor meta-representation.
|
||||
|
||||
Arguments:
|
||||
- value: The value of the constructor in the meta representation.
|
||||
Value value
|
||||
|
||||
## UNSTABLE
|
||||
@ -56,14 +58,18 @@ type Constructor
|
||||
|
||||
Returns a vector of field names defined by a constructor.
|
||||
fields : Vector
|
||||
fields self = Vector.from_polyglot_array (get_constructor_fields self.value)
|
||||
fields self =
|
||||
c = self.value ...
|
||||
Vector.from_polyglot_array (get_constructor_fields c)
|
||||
|
||||
## UNSTABLE
|
||||
ADVANCED
|
||||
|
||||
Returns the name of a constructor.
|
||||
name : Text
|
||||
name self = get_constructor_name self.value
|
||||
name self =
|
||||
c = self.value ...
|
||||
get_constructor_name c
|
||||
|
||||
## UNSTABLE
|
||||
ADVANCED
|
||||
@ -74,26 +80,28 @@ type Constructor
|
||||
- fields: A vector of arguments to pass to the constructor when creating the
|
||||
new atom.
|
||||
new : Vector -> Any
|
||||
new self fields = new_atom self.value fields.to_array
|
||||
new self fields =
|
||||
ctor = self.value ...
|
||||
new_atom ctor fields.to_array
|
||||
|
||||
## UNSTABLE
|
||||
ADVANCED
|
||||
|
||||
A primitive value meta-representation.
|
||||
|
||||
Arguments:
|
||||
- value: The value of the primitive object in the meta representation.
|
||||
type Primitive
|
||||
## UNSTABLE
|
||||
ADVANCED
|
||||
|
||||
A primitive value meta-representation.
|
||||
|
||||
Arguments:
|
||||
- value: The value of the primitive object in the meta representation.
|
||||
Value value
|
||||
|
||||
## UNSTABLE
|
||||
ADVANCED
|
||||
|
||||
An unresolved symbol meta-representation.
|
||||
|
||||
Arguments:
|
||||
- value: The value of the unresolved symbol in the meta representation.
|
||||
type Unresolved_Symbol
|
||||
## UNSTABLE
|
||||
ADVANCED
|
||||
|
||||
An unresolved symbol meta-representation.
|
||||
|
||||
Arguments:
|
||||
- value: The value of the unresolved symbol in the meta representation.
|
||||
Value value
|
||||
|
||||
## UNSTABLE
|
||||
@ -122,24 +130,24 @@ type Unresolved_Symbol
|
||||
scope : Any
|
||||
scope self = get_unresolved_symbol_scope self.value
|
||||
|
||||
## UNSTABLE
|
||||
ADVANCED
|
||||
|
||||
An error meta-representation, containing the payload of a dataflow error.
|
||||
|
||||
Arguments:
|
||||
- value: The payload of the error.
|
||||
type Error
|
||||
## UNSTABLE
|
||||
ADVANCED
|
||||
|
||||
An error meta-representation, containing the payload of a dataflow error.
|
||||
|
||||
Arguments:
|
||||
- value: The payload of the error.
|
||||
Value value
|
||||
|
||||
## UNSTABLE
|
||||
ADVANCED
|
||||
|
||||
A polyglot value meta-representation.
|
||||
|
||||
Arguments:
|
||||
- value: The polyglot value contained in the meta representation.
|
||||
type Polyglot
|
||||
## UNSTABLE
|
||||
ADVANCED
|
||||
|
||||
A polyglot value meta-representation.
|
||||
|
||||
Arguments:
|
||||
- value: The polyglot value contained in the meta representation.
|
||||
Value value
|
||||
|
||||
## UNSTABLE
|
||||
@ -188,7 +196,7 @@ Base_Error.is_a self typ = typ==Any || typ==Base_Error
|
||||
|
||||
Arguments:
|
||||
- atom: The atom to obtain the constructor for.
|
||||
get_atom_constructor : Atom -> Constructor
|
||||
get_atom_constructor : Atom -> Any
|
||||
get_atom_constructor atom = @Builtin_Method "Meta.get_atom_constructor"
|
||||
|
||||
## PRIVATE
|
||||
@ -243,7 +251,7 @@ get_unresolved_symbol_scope symbol = @Builtin_Method "Meta.get_unresolved_symbol
|
||||
|
||||
Arguments:
|
||||
- atom_constructor: The constructor from which to get the fields.
|
||||
get_constructor_fields : Constructor -> Array
|
||||
get_constructor_fields : Any -> Array
|
||||
get_constructor_fields atom_constructor = @Builtin_Method "Meta.get_constructor_fields"
|
||||
|
||||
## PRIVATE
|
||||
@ -252,7 +260,7 @@ get_constructor_fields atom_constructor = @Builtin_Method "Meta.get_constructor_
|
||||
|
||||
Arguments:
|
||||
- atom_constructor: The atom constructor from which to obtain the name.
|
||||
get_constructor_name : Constructor -> Text
|
||||
get_constructor_name : Any -> Text
|
||||
get_constructor_name atom_constructor = @Builtin_Method "Meta.get_constructor_name"
|
||||
|
||||
## PRIVATE
|
||||
@ -262,7 +270,7 @@ get_constructor_name atom_constructor = @Builtin_Method "Meta.get_constructor_na
|
||||
Arguments:
|
||||
- constructor: The constructor for the atom to create.
|
||||
- fields: The arguments to pass to constructor.
|
||||
new_atom : Constructor -> Array -> Atom
|
||||
new_atom : Any -> Array -> Atom
|
||||
new_atom constructor fields = @Builtin_Method "Meta.new_atom"
|
||||
|
||||
## UNSTABLE
|
||||
@ -321,7 +329,7 @@ is_a value typ = if is_same_object value typ then True else
|
||||
meta_val = meta value
|
||||
case meta_val of
|
||||
_ : Atom -> if is_atom typ then typ == value else
|
||||
meta_val.constructor == typ
|
||||
meta_val.constructor.value == typ
|
||||
_ : Constructor ->
|
||||
meta_typ = meta typ
|
||||
case meta_typ of
|
||||
|
@ -1419,7 +1419,7 @@ type Table
|
||||
self.write file format=base_format on_existing_file match_columns on_problems
|
||||
_ ->
|
||||
Panic.catch No_Such_Method.Error (format.write_table file self on_existing_file match_columns on_problems) _->
|
||||
name = Meta.get_constructor_name (Meta.meta format).constructor
|
||||
name = (Meta.meta format).constructor.name
|
||||
Error.throw (Illegal_Argument.Error ("Saving a Table as " + name + " is not supported."))
|
||||
|
||||
## Creates a text representation of the table using the CSV format.
|
||||
|
@ -20,7 +20,7 @@ test_problem_handling : (Problem_Behavior -> Any) -> Vector Any -> (Any -> Nothi
|
||||
test_problem_handling action expected_problems result_checker =
|
||||
error_checker error_result =
|
||||
first_problem = expected_problems.first
|
||||
first_problem_type = Meta.meta first_problem . constructor
|
||||
first_problem_type = Meta.meta first_problem . constructor . value
|
||||
error_result . should_fail_with first_problem_type frames_to_skip=3
|
||||
error_result.catch . should_equal first_problem frames_to_skip=3
|
||||
warnings_checker warnings =
|
||||
|
@ -31,14 +31,20 @@ spec = Test.group "Meta-Value Manipulation" <|
|
||||
Test.specify "should allow manipulating atoms" <|
|
||||
atom = My_Type.Value 1 "foo" Nothing
|
||||
meta_atom = Meta.meta atom
|
||||
meta_atom.constructor.should_equal My_Type.Value
|
||||
meta_atom.constructor.value.should_equal My_Type.Value
|
||||
meta_atom.fields.should_equal [1, "foo", Nothing]
|
||||
Meta.meta (meta_atom.constructor) . new [1, "foo", Nothing] . should_equal atom
|
||||
Meta.meta (meta_atom.constructor.value) . new [1, "foo", Nothing] . should_equal atom
|
||||
Test.specify "should allow getting a value's constructor's name" <|
|
||||
Meta.meta List.Nil . constructor . name . should_equal "Nil"
|
||||
Meta.meta (List.Cons 1 List.Nil) . constructor . name . should_equal "Cons"
|
||||
Test.specify "should allow getting a value's constructor's fields" <|
|
||||
Meta.meta List.Nil . constructor . fields . should_equal []
|
||||
Meta.meta (List.Cons 1 List.Nil) . constructor . fields . should_equal ["x", "xs"]
|
||||
Test.specify "should allow creating atoms from atom constructors" <|
|
||||
atom_1 = Meta.new_atom My_Type.Value [1,"foo", Nothing]
|
||||
(Meta.meta atom_1).constructor . should_equal My_Type.Value
|
||||
(Meta.meta atom_1).constructor.value . should_equal My_Type.Value
|
||||
atom_2 = Meta.new_atom My_Type.Value [1,"foo", Nothing].to_array
|
||||
(Meta.meta atom_2).constructor . should_equal My_Type.Value
|
||||
(Meta.meta atom_2).constructor.value . should_equal My_Type.Value
|
||||
Test.specify "should correctly return representations of different classes of objects" <|
|
||||
Meta.meta 1 . should_equal (Meta.Primitive.Value 1)
|
||||
Meta.meta "foo" . should_equal (Meta.Primitive.Value "foo")
|
||||
|
Loading…
Reference in New Issue
Block a user