Skip to content

Commit

Permalink
Fix on argument for Vector.sort (#7751)
Browse files Browse the repository at this point in the history
Fix treatment of the `on` argument of `Vector.sort`.
  • Loading branch information
Akirathan authored Sep 7, 2023
1 parent 5ab74b5 commit 6876867
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -719,8 +719,6 @@ private class CompareFromUnresolvedSymbol extends Compare {
private final MethodResolverNode methodResolverNode;
private final TypesLibrary typesLibrary;

private @CompilerDirectives.CompilationFinal Function resolvedFunction;

private CompareFromUnresolvedSymbol(UnresolvedSymbol unresolvedSymbol,
MethodResolverNode methodResolvedNode,
TypesLibrary typesLibrary) {
Expand All @@ -732,22 +730,15 @@ private CompareFromUnresolvedSymbol(UnresolvedSymbol unresolvedSymbol,

@Override
boolean hasFunctionSelfArgument(Object definedOn) {
ensureSymbolIsResolved(definedOn);
var resolvedFunction = methodResolverNode.expectNonNull(definedOn, typesLibrary.getType(definedOn), unresolvedSymbol);
return resolvedFunction.getSchema().getArgumentsCount() > 0 &&
resolvedFunction.getSchema().getArgumentInfos()[0].getName().equals("self");

}

@Override
Function get(Object arg) {
ensureSymbolIsResolved(arg);
return resolvedFunction;
}

private void ensureSymbolIsResolved(Object definedOn) {
if (resolvedFunction == null) {
resolvedFunction = methodResolverNode.expectNonNull(definedOn, typesLibrary.getType(definedOn), unresolvedSymbol);
}
return methodResolverNode.expectNonNull(arg, typesLibrary.getType(arg), unresolvedSymbol);
}
}

Expand Down
6 changes: 6 additions & 0 deletions test/Tests/src/Data/Vector_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,12 @@ type_spec name alter = Test.group name <|
Test.specify "should return a vector containing only unique elements up to some criteria" <|
alter [Pair.new 1 "a", Pair.new 2 "b", Pair.new 1 "c"] . distinct (on = _.first) . should_equal [Pair.new 1 "a", Pair.new 2 "b"]

Test.specify "should be able to sort a heterogenous vector" <|
arr = [ 1, 1.3, "hi", Date.today, Date_Time.now, [ 0 ] ]
(arr.sort on=(.to_text) . map .to_text) . should_equal (arr.map .to_text . sort)
(arr.sort on=(_.to_text) . map .to_text) . should_equal (arr.map .to_text . sort)
(arr.sort on=(x-> x.to_text) . map .to_text) . should_equal (arr.map .to_text . sort)

Test.specify "should be able to sort a polyglot vector" <|
input = "beta".utf_8
expected = "abet".utf_8
Expand Down

0 comments on commit 6876867

Please sign in to comment.