Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check type of self in static dispatch #8867

Merged
merged 39 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
920e1e6
add tests for self type check
radeusgd Jan 25, 2024
738dba7
probable fix for https://github.com/enso-org/enso/issues/8706
radeusgd Jan 25, 2024
deda165
add self type ascription to the static method variant
radeusgd Jan 25, 2024
f974567
remove TODO
radeusgd Jan 25, 2024
15c1ada
fmt
radeusgd Jan 25, 2024
0f195bf
changelog
radeusgd Jan 25, 2024
9da0231
add test case for suspended default arg + fix its location
radeusgd Jan 25, 2024
14ac342
scalafmt
radeusgd Jan 25, 2024
9bd0070
CR
radeusgd Jan 26, 2024
592c41d
enable pending tests in binary dispatch test
radeusgd Feb 2, 2024
e01ef20
WIP: adding common ops
radeusgd Feb 3, 2024
5879371
checkpoint
radeusgd Feb 3, 2024
5ed8096
checkpoint: migrating to array helpers
radeusgd Feb 5, 2024
dd05f47
checkpoint
radeusgd Feb 5, 2024
1db7b0e
moved common methods from Vector to Array_Like_Helpers
radeusgd Feb 5, 2024
256a953
moving builtins
radeusgd Feb 6, 2024
c2147f0
comment on necessity of this test
radeusgd Feb 6, 2024
2fb7648
better error location
radeusgd Feb 6, 2024
d02f0a1
implemented Self type resolution
radeusgd Feb 7, 2024
f09f4cc
fix warnings dispatch
radeusgd Feb 9, 2024
a817116
Revert array helpers refactor
radeusgd Feb 9, 2024
b40b5ef
array gets converted to vector to be able to call static vector metho…
radeusgd Feb 9, 2024
4bffe45
remove is_same_object check on Array_Slice as it is no longer the sam…
radeusgd Feb 9, 2024
a6c2051
scalafmt
radeusgd Feb 9, 2024
7dce799
refactor self type resolution
radeusgd Feb 9, 2024
a7fd250
refactor self type resolution, pt. 2
radeusgd Feb 9, 2024
7f902ca
fix ?
radeusgd Feb 9, 2024
aa46001
fix seemingly unrelated test?
radeusgd Feb 9, 2024
28735bf
more fixes
radeusgd Feb 9, 2024
d61e4c9
Merge branch 'develop' into wip/radeusgd/8805-self-type-check
radeusgd Feb 10, 2024
28a4e34
call member on converted vector instead of using static syntax - this…
radeusgd Feb 10, 2024
a33a2bf
Merge branch 'develop' into wip/radeusgd/8805-self-type-check
JaroslavTulach Feb 12, 2024
f70776f
Merge branch 'develop' into wip/radeusgd/8805-self-type-check
radeusgd Feb 13, 2024
468a539
Merge branch 'develop' into wip/radeusgd/8805-self-type-check
radeusgd Feb 13, 2024
651931d
fix Empty_Error
radeusgd Feb 13, 2024
f29f313
Revert "Revert array helpers refactor"
radeusgd Feb 13, 2024
32ecd32
fixes after revert + updates
radeusgd Feb 13, 2024
038af50
Merge branch 'develop' into wip/radeusgd/8805-self-type-check
radeusgd Feb 14, 2024
f17e643
javafmt
radeusgd Feb 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,7 @@
- [DataflowError.withoutTrace doesn't store stacktrace][8608]
- [Derive --in-project from --run source location][8775]
- [Binary operator resolution based on that value][8779]
- [Check type of `self` when calling a method using the static syntax][8867]
- [Execute and debug individual Enso files in VSCode extension][8923]

[3227]: https://github.com/enso-org/enso/pull/3227
Expand Down Expand Up @@ -1200,6 +1201,7 @@
[8608]: https://github.com/enso-org/enso/pull/8608
[8775]: https://github.com/enso-org/enso/pull/8775
[8779]: https://github.com/enso-org/enso/pull/8779
[8867]: https://github.com/enso-org/enso/pull/8867
[8923]: https://github.com/enso-org/enso/pull/8923

# Enso 2.0.0-alpha.18 (2021-10-12)
Expand Down
86 changes: 53 additions & 33 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Data/Array.enso
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ type Array
[My_Type.Value 'hello', 1].to_array.sort == [1, My_Type.Value 'hello'].to_array
sort : Sort_Direction -> (Any -> Any)|Nothing -> (Any -> Any -> (Ordering|Nothing))|Nothing -> Problem_Behavior -> Vector Any ! Incomparable_Values
sort self (order = Sort_Direction.Ascending) on=Nothing by=Nothing on_incomparable=Problem_Behavior.Ignore =
Vector.sort self order on by on_incomparable
Array_Like_Helpers.sort self order on by on_incomparable

## ALIAS first, last, sample, slice
GROUP Selections
Expand All @@ -159,7 +159,8 @@ type Array
If a `Range`, the selection is specified by two indices, from and to.
@range Index_Sub_Range.default_widget
take : (Index_Sub_Range | Range | Integer) -> Vector Any
take self range=(Index_Sub_Range.First 1) = Vector.take self range
take self range=(Index_Sub_Range.First 1) =
Array_Like_Helpers.take self range

## ALIAS skip
GROUP Selections
Expand All @@ -173,7 +174,8 @@ type Array
If a `Range`, the selection is specified by two indices, from and to.
@range Index_Sub_Range.default_widget
drop : (Index_Sub_Range | Range | Integer) -> Vector Any
drop self range=(Index_Sub_Range.First 1) = Vector.drop self range
drop self range=(Index_Sub_Range.First 1) =
Array_Like_Helpers.drop self range

## GROUP Calculations
Inserts the given item into the array at the given index.
Expand All @@ -192,7 +194,8 @@ type Array
['a', 'b', 'c'].to_array.insert -1 'X' == ['a', 'b', 'X', 'c'].to_array
['a', 'b', 'c'].to_array.insert item='X' == ['a', 'b', 'c', 'X'].to_array
insert : Integer -> Any -> Vector ! Index_Out_Of_Bounds
insert self at=self.length item=Nothing = Vector.insert self at item
insert self at=self.length item=Nothing =
Array_Like_Helpers.insert self at item

## GROUP Selections
Removes the item at the given index from the array.
Expand All @@ -202,7 +205,7 @@ type Array
If the index is less than 0, the index will be counted back from the
end.
remove : Integer -> Vector
remove self at=-1 = Vector.remove self at
remove self at=-1 = Array_Like_Helpers.remove self at

## GROUP Selections
ICON select_row
Expand Down Expand Up @@ -262,7 +265,8 @@ type Array

["ab", "abab", "aba", "bbb"].to_array.index_of (s-> s == s.reverse) == 2
index_of : (Any | Filter_Condition | (Any -> Boolean)) -> Integer -> Integer | Nothing
index_of self condition start=0 = Vector.index_of self condition start
index_of self condition (start : Integer = 0) =
Array_Like_Helpers.index_of self condition start

## GROUP Values
Returns the last index of an element in the array.
Expand All @@ -284,7 +288,8 @@ type Array

["ab", "abab", "aba", "bbb"].to_array.last_index_of (s-> s == s.reverse) == 3
last_index_of : (Any | Filter_Condition | (Any -> Boolean)) -> Integer -> Integer | Nothing
last_index_of self condition start=-1 = Vector.last_index_of self condition start
last_index_of self condition (start : Integer = -1) =
Array_Like_Helpers.last_index_of self condition start

## GROUP Logical
ICON metadata
Expand All @@ -299,7 +304,7 @@ type Array

## Converts the array to a list with the same elements.
to_list : List
to_list self = Vector.to_list self
to_list self = Array_Like_Helpers.to_list self

## GROUP Selections
ICON preparation
Expand All @@ -325,7 +330,7 @@ type Array

[Pair 1 "a", Pair 2 "b", Pair 1 "c"].to_array . distinct (on = _.first) == [Pair 1 "a", Pair 2 "b"].to_array
distinct : (Any -> Any) -> Vector Any
distinct self (on = x->x) = Vector.distinct self on
distinct self (on = x->x) = Array_Like_Helpers.distinct self on

## ICON dataframe_map_column
Applies a function to each element of the array, returning the `Vector` of
Expand Down Expand Up @@ -363,7 +368,8 @@ type Array

[1, 2, 3].to_array . map +1
map : (Any -> Any) -> Problem_Behavior | No_Wrap -> Vector Any
map self function on_problems=Problem_Behavior.Report_Error = Vector.map self function on_problems
map self function on_problems=Problem_Behavior.Report_Error =
Array_Like_Helpers.map self function on_problems

## Applies a function to each element of the array, returning the `Vector`
that contains all results concatenated.
Expand Down Expand Up @@ -400,7 +406,8 @@ type Array

[0, 1, 2].to_array . flat_map (n -> Vector.fill n n)
flat_map : (Any -> Vector Any) -> Problem_Behavior | No_Wrap -> Vector Any
flat_map self function on_problems=Problem_Behavior.Report_Error = Vector.flat_map self function on_problems
flat_map self function on_problems=Problem_Behavior.Report_Error =
Array_Like_Helpers.flat_map self function on_problems

## GROUP Selections
ICON preparation
Expand All @@ -418,7 +425,7 @@ type Array
[1, 2, 3, 4, 5].to_array.filter (> 3)
[1, 2, 3, 4, 5].to_array.filter (Filter_Condition.Greater than=3)
filter : (Filter_Condition | (Any -> Boolean)) -> Vector Any
filter self filter = Vector.filter self filter
filter self filter = Array_Like_Helpers.filter self filter

## GROUP Calculations
Transforms an array of arrays into a `Vector` of inner elements - removes
Expand All @@ -429,12 +436,13 @@ type Array

[[1, 2, 3].to_array, [4, 10].to_array, [].to_array, [0].to_array, [0].to_array].to_array . flatten == [1, 2, 3, 4, 10, 0, 0].to_array
flatten : Vector Any
flatten self = Vector.flatten self
flatten self = Array_Like_Helpers.flatten self

## PRIVATE
ADVANCED
short_display_text : Integer -> Text
short_display_text self max_entries=10 = Vector.short_display_text self max_entries
short_display_text self max_entries=10 =
Array_Like_Helpers.short_display_text self max_entries

## Combines all the elements of the array, by iteratively applying the
passed function with the next element of the array. After each step the
Expand All @@ -449,7 +457,8 @@ type Array

[1, 2, 3].to_array.running_fold 0 (+)
running_fold : Any -> (Any -> Any -> Any) -> Vector Any
running_fold self init function = Vector.running_fold self init function
running_fold self init function =
Array_Like_Helpers.running_fold self init function

## ICON dataframe_map_column
Combines all the elements of the array, by iteratively applying the
Expand All @@ -469,7 +478,8 @@ type Array

[0, 1, 2].to_array . fold 0 (+)
fold : Any -> (Any -> Any -> Any) -> Any
fold self init function = Vector.fold self init function
fold self init function =
Array_Like_Helpers.fold self init function

## ICON dataframe_map_column
Combines all the elements of the array, by iteratively applying the
Expand All @@ -485,7 +495,8 @@ type Array

[0, 1, 2].to_array . fold_with_index 0 (s->i->e->s+i+e)
fold_with_index : Any -> (Any -> Integer -> Any -> Any) -> Any
fold_with_index self init function = Vector.fold_with_index self init function
fold_with_index self init function =
Array_Like_Helpers.fold_with_index self init function

## GROUP Calculations
Extend `self` array to the length of `n` appending elements `elem` to
Expand All @@ -508,7 +519,7 @@ type Array

[1, 2, 3, 4, 5].to_array.pad 5 0 == [1, 2, 3, 4, 5].to_array
pad : Integer -> Any -> Vector Any
pad self n elem = Vector.pad self n elem
pad self n elem = Array_Like_Helpers.pad self n elem

## GROUP Selections
ICON split_text
Expand Down Expand Up @@ -536,7 +547,8 @@ type Array

[1, 2, 3, 4, 5].to_array.partition (x -> x % 2 == 0) == (Pair [2, 4].to_array [1, 3, 5].to_array)
partition : (Filter_Condition | (Any -> Boolean)) -> Pair (Vector Any) (Vector Any)
partition self condition = Vector.partition self condition
partition self condition =
Array_Like_Helpers.partition self condition

## Partitions the array into `Vector`s of elements which satisfy a given
predicate and ones that do not.
Expand All @@ -557,7 +569,8 @@ type Array

["a", "b", "c", "d"].to_array.partition_with_index (ix -> _ -> ix % 2 == 0) == (Pair ["a", "c"].to_array ["b", "d"].to_array)
partition_with_index : (Integer -> Any -> Boolean) -> Pair (Vector Any) (Vector Any)
partition_with_index self predicate = Vector.partition_with_index self predicate
partition_with_index self predicate =
Array_Like_Helpers.partition_with_index self predicate

## Applies a function to each element of the array, returning the `Vector`
of results.
Expand Down Expand Up @@ -597,7 +610,8 @@ type Array

[1, 2, 3].to_array.map_with_index (+)
map_with_index : (Integer -> Any -> Any) -> Problem_Behavior | No_Wrap -> Vector Any
map_with_index self function on_problems=Problem_Behavior.Report_Error = Vector.map_with_index self function on_problems
map_with_index self function on_problems=Problem_Behavior.Report_Error =
Array_Like_Helpers.map_with_index self function on_problems

## PRIVATE
Creates a new array with the skipping elements until `start` and then
Expand All @@ -612,7 +626,8 @@ type Array

[1, 2, 3, 4, 5, 6, 7, 8].to_array.slice 2 5 == [3, 4, 5].to_array
slice : Integer -> Integer -> Vector Any
slice self start end = Vector.slice self start end
slice self start end =
Array_Like_Helpers.slice self start end

## GROUP Selections
Returns the first element of the array that satisfies the condition or
Expand All @@ -630,7 +645,8 @@ type Array

[1, 2, 3, 4, 5].to_array.find (> 3)
find : (Filter_Condition | (Any -> Boolean)) -> Integer -> Any -> Any
find self condition start=0 ~if_missing=(Error.throw Not_Found) = Vector.find self condition start if_missing
find self condition (start : Integer = 0) ~if_missing=(Error.throw Not_Found) =
Array_Like_Helpers.find self condition start if_missing

## ICON select_row
Gets an element from the array at a specified index (0-based).
Expand All @@ -642,7 +658,8 @@ type Array
of the array, i.e. -1 will correspond to the last element.
- if_missing: The value to return if the index is out of bounds.
get : Integer -> Any -> Any
get self index ~if_missing=Nothing = Vector.get self index if_missing
get self index ~if_missing=Nothing =
Array_Like_Helpers.get self index if_missing

## GROUP Logical
ICON metadata
Expand All @@ -669,7 +686,8 @@ type Array

[0, 10, 2, 2].to_array.filter (==) == [0, 2].to_array
filter_with_index : (Integer -> Any -> Boolean) -> Vector Any
filter_with_index self predicate = Vector.filter_with_index self predicate
filter_with_index self predicate =
Array_Like_Helpers.filter_with_index self predicate

## GROUP Calculations
ICON join
Expand All @@ -686,7 +704,8 @@ type Array

["foo", "bar", "baz"].to_array.join ", "
join : Text -> Text -> Text -> Text
join self separator="" prefix="" suffix="" = Vector.join self separator prefix suffix
join self separator:Text="" prefix:Text="" suffix:Text="" =
Array_Like_Helpers.join self separator prefix suffix

## PRIVATE
Generates a human-readable text representation of the array.
Expand All @@ -710,7 +729,8 @@ type Array

[0, 1, 2].to_array . reduce (+)
reduce : (Any -> Any -> Any) -> Any -> Any
reduce self function ~if_empty=(Error.throw (Empty_Error.Error Array)) = Vector.reduce self function if_empty
reduce self function ~if_empty=(Error.throw (Empty_Error.Error Array)) =
Array_Like_Helpers.reduce self function if_empty

## GROUP Logical
ICON preparation
Expand All @@ -730,7 +750,7 @@ type Array

[1, 2, 3, 4, 5].to_array.any (x-> x%2 == 0)
any : (Filter_Condition | (Any -> Boolean)) -> Boolean
any self condition = Vector.any self condition
any self condition = Array_Like_Helpers.any self condition

## GROUP Logical
ICON preparation
Expand All @@ -750,7 +770,7 @@ type Array

[-1, 1, 5, 8].to_array.all (x-> x%2 == 0)
all : (Filter_Condition | (Any -> Boolean)) -> Boolean
all self condition = Vector.all self condition
all self condition = Array_Like_Helpers.all self condition

## GROUP Logical
ICON preparation
Expand Down Expand Up @@ -831,7 +851,7 @@ type Array

[1, 2].to_array.reverse
reverse : Vector Any
reverse self = Vector.reverse self
reverse self = Array_Like_Helpers.reverse self

## PRIVATE
ADVANCED
Expand All @@ -848,7 +868,7 @@ type Array

[1, 2, 3, 4, 5].to_array . each IO.println
each : (Any -> Any) -> Nothing
each self f = Vector.each self f
each self f = Array_Like_Helpers.each self f

## PRIVATE
ADVANCED
Expand All @@ -868,7 +888,7 @@ type Array

[1, 2, 3, 4, 5].to_array . each_with_index (ix->elem-> IO.println Pair ix elem)
each_with_index : (Integer -> Any -> Any) -> Nothing
each_with_index self f = Vector.each_with_index self f
each_with_index self f = Array_Like_Helpers.each_with_index self f

## ALIAS append, concatenate, union
GROUP Operators
Expand All @@ -884,4 +904,4 @@ type Array

[1].to_array + [2].to_array
+ : Vector Any -> Vector Any
+ self that = Vector.+ self that
+ self that = Array_Like_Helpers.plus self that
6 changes: 3 additions & 3 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Data/List.enso
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ type List

example_first = Examples.list.find (> 2)
find : (Filter_Condition | (Any -> Boolean)) -> Integer -> Any -> Any
find self condition start=0 ~if_missing=(Error.throw Not_Found) =
find self condition (start : Integer = 0) ~if_missing=(Error.throw Not_Found) =
predicate = unify_condition_or_predicate condition
case start.signum of
-1 ->
Expand Down Expand Up @@ -583,7 +583,7 @@ type List

[1, 2, 3, 4, 5].find (> 3)
index_of : (Any | Filter_Condition | (Any -> Boolean)) -> Integer -> Integer | Nothing
index_of self condition start=0 = case start.signum of
index_of self condition (start : Integer = 0) = case start.signum of
-1 ->
node_and_index = find_node_from_end self start
found = node_and_index.first.index_of condition 0
Expand Down Expand Up @@ -611,7 +611,7 @@ type List

[1, 2, 3, 4, 5].find (> 3)
last_index_of : (Any | Filter_Condition | (Any -> Boolean)) -> Integer -> Integer | Nothing
last_index_of self condition start=-1 = case self of
last_index_of self condition (start : Integer = -1) = case self of
Nil -> if start == -1 || start == 0 then Nothing else Error.throw (Index_Out_Of_Bounds.Error start 0)
Cons _ _ ->
length = self.length
Expand Down
6 changes: 3 additions & 3 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Data/Pair.enso
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ type Pair

Pair.new 1 6 .find (> 3)
find : (Any -> Boolean) -> Integer -> Any -> Any
find self predicate start=0 ~if_missing=(Error.throw Not_Found) =
find self predicate (start : Integer = 0) ~if_missing=(Error.throw Not_Found) =
check_start_valid start used_start->
if used_start<1 && predicate self.first then self.first else
if used_start<2 && predicate self.second then self.second else
Expand All @@ -169,7 +169,7 @@ type Pair
Pair.new 1 2 . index_of 2 == 1
Pair.new 2 2 . index_of 2 == 0
index_of : (Any | (Any -> Boolean)) -> Integer -> Integer | Nothing
index_of self element start=0 = check_start_valid start used_start->
index_of self element (start : Integer = 0) = check_start_valid start used_start->
predicate = case element of
_ : Function -> element
_ -> (==element)
Expand All @@ -192,7 +192,7 @@ type Pair

Pair.new 2 2 . last_index_of 2 == 1
last_index_of : (Any | (Any -> Boolean)) -> Integer -> Integer | Nothing
last_index_of self element start=-1 = check_start_valid start max=2 used_start->
last_index_of self element (start : Integer = -1) = check_start_valid start max=2 used_start->
predicate = case element of
_ : Function -> element
_ -> (==element)
Expand Down
Loading
Loading