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 29 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -1040,6 +1040,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]

[3227]: https://github.com/enso-org/enso/pull/3227
[3248]: https://github.com/enso-org/enso/pull/3248
Expand Down Expand Up @@ -1195,6 +1196,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

# Enso 2.0.0-alpha.18 (2021-10-12)

Expand Down
68 changes: 34 additions & 34 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Data/Array.enso
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
Vector.sort (Vector.from_polyglot_array self) order on by on_incomparable

## ALIAS first, last, sample, slice
GROUP Selections
Expand All @@ -159,7 +159,7 @@ 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) = Vector.take (Vector.from_polyglot_array self) range

## ALIAS skip
GROUP Selections
Expand All @@ -173,7 +173,7 @@ 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) = Vector.drop (Vector.from_polyglot_array self) range

## GROUP Calculations
Inserts the given item into the array at the given index.
Expand All @@ -192,7 +192,7 @@ 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 = Vector.insert (Vector.from_polyglot_array self) at item

## GROUP Selections
Removes the item at the given index from the array.
Expand All @@ -202,7 +202,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 = Vector.remove (Vector.from_polyglot_array self) at

## GROUP Selections
ICON select_row
Expand Down Expand Up @@ -262,7 +262,7 @@ 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=0 = Vector.index_of (Vector.from_polyglot_array self) condition start

## GROUP Values
Returns the last index of an element in the array.
Expand All @@ -284,7 +284,7 @@ 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=-1 = Vector.last_index_of (Vector.from_polyglot_array self) condition start

## GROUP Logical
ICON metadata
Expand All @@ -299,7 +299,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 = Vector.to_list (Vector.from_polyglot_array self)

## GROUP Selections
ICON preparation
Expand All @@ -325,7 +325,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) = Vector.distinct (Vector.from_polyglot_array 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 +363,7 @@ 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 = Vector.map (Vector.from_polyglot_array 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 +400,7 @@ 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 = Vector.flat_map (Vector.from_polyglot_array self) function on_problems

## GROUP Selections
ICON preparation
Expand All @@ -418,7 +418,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 = Vector.filter (Vector.from_polyglot_array self) filter

## GROUP Calculations
Transforms an array of arrays into a `Vector` of inner elements - removes
Expand All @@ -429,12 +429,12 @@ 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 = Vector.flatten (Vector.from_polyglot_array 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 = Vector.short_display_text (Vector.from_polyglot_array 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 +449,7 @@ 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 = Vector.running_fold (Vector.from_polyglot_array self) init function

## ICON dataframe_map_column
Combines all the elements of the array, by iteratively applying the
Expand All @@ -469,7 +469,7 @@ 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 = Vector.fold (Vector.from_polyglot_array self) init function

## ICON dataframe_map_column
Combines all the elements of the array, by iteratively applying the
Expand All @@ -485,7 +485,7 @@ 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 = Vector.fold_with_index (Vector.from_polyglot_array self) init function

## GROUP Calculations
Extend `self` array to the length of `n` appending elements `elem` to
Expand All @@ -508,7 +508,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 = Vector.pad (Vector.from_polyglot_array self) n elem

## GROUP Selections
ICON split_text
Expand Down Expand Up @@ -536,7 +536,7 @@ 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 = Vector.partition (Vector.from_polyglot_array self) condition

## Partitions the array into `Vector`s of elements which satisfy a given
predicate and ones that do not.
Expand All @@ -557,7 +557,7 @@ 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 = Vector.partition_with_index (Vector.from_polyglot_array self) predicate

## Applies a function to each element of the array, returning the `Vector`
of results.
Expand Down Expand Up @@ -597,7 +597,7 @@ 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 = Vector.map_with_index (Vector.from_polyglot_array self) function on_problems

## PRIVATE
Creates a new array with the skipping elements until `start` and then
Expand All @@ -612,7 +612,7 @@ 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 = Vector.slice (Vector.from_polyglot_array self) start end

## GROUP Selections
Returns the first element of the array that satisfies the condition or
Expand All @@ -630,7 +630,7 @@ 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=0 ~if_missing=(Error.throw Not_Found) = Vector.find (Vector.from_polyglot_array self) condition start if_missing

## ICON select_row
Gets an element from the array at a specified index (0-based).
Expand All @@ -642,7 +642,7 @@ 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 = Vector.get (Vector.from_polyglot_array self) index if_missing

## GROUP Logical
ICON metadata
Expand All @@ -669,7 +669,7 @@ 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 = Vector.filter_with_index (Vector.from_polyglot_array self) predicate

## GROUP Calculations
ICON join
Expand All @@ -686,7 +686,7 @@ 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="" prefix="" suffix="" = Vector.join (Vector.from_polyglot_array self) separator prefix suffix

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

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

## GROUP Logical
ICON preparation
Expand All @@ -730,7 +730,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 = Vector.any (Vector.from_polyglot_array self) condition

## GROUP Logical
ICON preparation
Expand All @@ -750,7 +750,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 = Vector.all (Vector.from_polyglot_array self) condition

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

## Returns the array as a `Vector`.
to_vector : Vector
to_vector self = Vector.from_polyglot_array self
to_vector self = Vector.from_polyglot_array (Vector.from_polyglot_array self)

## GROUP Selections
Reverses the array, returning a `Vector` with the same elements, but in
Expand All @@ -831,7 +831,7 @@ type Array

[1, 2].to_array.reverse
reverse : Vector Any
reverse self = Vector.reverse self
reverse self = Vector.reverse (Vector.from_polyglot_array self)

## PRIVATE
ADVANCED
Expand All @@ -848,7 +848,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 = Vector.each (Vector.from_polyglot_array self) f

## PRIVATE
ADVANCED
Expand All @@ -868,7 +868,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 = Vector.each_with_index (Vector.from_polyglot_array self) f

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

[1].to_array + [2].to_array
+ : Vector Any -> Vector Any
+ self that = Vector.+ self that
+ self that = Vector.+ (Vector.from_polyglot_array self) that
8 changes: 4 additions & 4 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Warning.enso
Expand Up @@ -50,11 +50,11 @@ type Warning

Arguments:
- warning_type: The type to throw if attached to the value. Defaults to all warnings.
throw_on_warning : Any -> Any
throw_on_warning self warning_type=Any =
warnings = Warning.get_all self
throw_on_warning : Any -> Any -> Any
throw_on_warning value warning_type=Any =
warnings = Warning.get_all value
first = warnings.find (w-> w.value.is_a warning_type) if_missing=Nothing
if first.is_nothing then self else Error.throw first.value
if first.is_nothing then value else Error.throw first.value

## PRIVATE
ADVANCED
Expand Down
Expand Up @@ -998,6 +998,13 @@ object BindingsMap {
s"The name `${originalName.name}` could not be found"
}

/** A resolution error due to usage of Self type reference outside of a type scope.
*/
case object SelfTypeOutsideOfTypeDefinition extends ResolutionError {
override def explain(originalName: ir.Name): String =
s"The Self type is not applicable outside of a type definition"
}

/** A metadata-friendly storage for resolutions */
case class Resolution(target: ResolvedName) extends IRPass.IRMetadata {

Expand Down