> Error: Implicit coercion of a value of type (a:Object,b:Object)=>int to
an unrelated type (values:Object,obj:Object,fieldsForCompare?:Array)=>int.

This error appears to be correct because you have omitted the third
parameter. The argument may be omitted only when calling the function. It
can’t be omitted when defining the function. You’d have a similar error if
an interface had an optional parameter, and you tried to define a method on
an implementing class that didn’t include the optional parameter.

> Error: Implicit coercion of a value of type Function to an unrelated type
(values:Object,obj:Object,fieldsForCompare?:Array)=>int.

This one seems like it might be a bug, though. The compiler may be ignoring
the function type expression somewhere.


--
Josh Tynjala
Bowler Hat LLC
https://bowlerhat.dev/


On Fri, Jan 30, 2026 at 5:10 AM Harbs <[email protected]> wrote:

> I tried to use them in the Sort classes, and I got the following error.
>
> Is this user error or a bug?
>
>
>      [java]
> /Users/harbs/Apache/royale-asjs/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/Sort.as(397):
> col: 30 Error: Implicit coercion of a value of type Function to an
> unrelated type (values:Object,obj:Object,fieldsForCompare?:Array)=>int.
>      [java]
>      [java]             compareForFind = this.compareFunction;
>      [java]                              ^
>      [java]
>      [java]
> /Users/harbs/Apache/royale-asjs/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/Sort.as(619):
> col: 21 Error: Implicit coercion of a value of type
> (a:Object,b:Object)=>int to an unrelated type
> (values:Object,obj:Object,fieldsForCompare?:Array)=>int.
>      [java]
>      [java]                     function (a:Object, b:Object):int
>      [java]                     ^
>      [java]
>      [java]
> /Users/harbs/Apache/royale-asjs/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/Sort.as(397):
> col: 30 Implicit coercion of a value of type Function to an unrelated type
> (values:Object,obj:Object,fieldsForCompare?:Array)=>int.
>      [java]
>      [java]             compareForFind = this.compareFunction;
>      [java]                              ^
>      [java]
>      [java]
> /Users/harbs/Apache/royale-asjs/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/Sort.as(619):
> col: 21 Implicit coercion of a value of type (a:Object,b:Object)=>int to an
> unrelated type (values:Object,obj:Object,fieldsForCompare?:Array)=>int.
>      [java]
>      [java]                     function (a:Object, b:Object):int
>      [java]                     ^
>
>
> Changes:
>
> diff --git
> a/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/ISort.as
> b/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/ISort.as
> index 14073e1da9..02a7bcc86d 100644
> ---
> a/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/ISort.as
> +++
> b/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/ISort.as
> @@ -123,13 +123,13 @@ public interface ISort {
>       *  @playerversion AIR 2.6
>       *  @productversion Flex 4.5
>       */
> -    function get compareFunction():Function;
> +    function get compareFunction():(values:Object, obj:Object,
> fieldsForCompare?:Array) => int;
>
>      /**
>       *  @deprecated A future release of Apache Flex SDK will remove this
> function. Please use the constructor
>       *  argument instead.
>       */
> -    function set compareFunction(value:Function):void;
> +    function set compareFunction(value:(values:Object, obj:Object,
> fieldsForCompare?:Array) => int):void;
>
>      /**
>       *  An <code>Array</code> of <code>ISortField</code> objects that
>
>
> diff --git
> a/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/Sort.as
> b/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/Sort.as
> index d16869fa1f..abec999093 100644
> ---
> a/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/Sort.as
> +++
> b/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/Sort.as
> @@ -186,7 +186,7 @@ public class Sort extends EventDispatcher implements
> ISort
>       *  @playerversion AIR 2.6
>       *  @productversion Royale 0.0
>       */
> -    public function Sort(fields:Array = null,
> customCompareFunction:Function = null, unique:Boolean = false)
> +    public function Sort(fields:Array = null,
> customCompareFunction:(values:Object, obj:Object, fieldsForCompare?:Array)
> => int = null, unique:Boolean = false)
>      {
>          super();
>
> @@ -236,7 +236,7 @@ public class Sort extends EventDispatcher implements
> ISort
>       *  @private
>       *  Storage for the compareFunction property.
>       */
> -    private var _compareFunction:Function;
> +    private var _compareFunction:(values:Object, obj:Object,
> fieldsForCompare?:Array) => int;
>
>      /**
>       *  @private
> @@ -253,7 +253,7 @@ public class Sort extends EventDispatcher implements
> ISort
>       *  @playerversion AIR 2.6
>       *  @productversion Royale 0.0
>       */
> -    public function get compareFunction():Function
> +    public function get compareFunction():(values:Object, obj:Object,
> fieldsForCompare?:Array) => int
>      {
>          return usingCustomCompareFunction ? _compareFunction :
> internalCompare;
>      }
> @@ -261,7 +261,7 @@ public class Sort extends EventDispatcher implements
> ISort
>      /**
>       *  @private
>       */
> -    public function set compareFunction(value:Function):void
> +    public function set compareFunction(value:(values:Object, obj:Object,
> fieldsForCompare?:Array) => int):void
>      {
>          _compareFunction = value;
>          usingCustomCompareFunction = _compareFunction != null;
> @@ -376,9 +376,9 @@ public class Sort extends EventDispatcher implements
> ISort
>                               values:Object,
>                               mode:String,
>                               returnInsertionIndex:Boolean = false,
> -                             compareFunction:Function = null):int
> +                             compareFunction:(values:Object, obj:Object,
> fieldsForCompare?:Array) => int = null):int
>      {
> -        var compareForFind:Function;
> +        var compareForFind:(values:Object, obj:Object,
> fieldsForCompare?:Array) => int;
>          var fieldsForCompare:Array;
>          var message:String;
>
> @@ -615,7 +615,7 @@ public class Sort extends EventDispatcher implements
> ISort
>              // the Sort.internalCompare function knows to use
> Sort._fields; that same logic
>              // needs to be part of calling a custom compareFunction. Of
> course, a user shouldn't
>              // be doing this -- so I wrap calls to compareFunction with
> _fields as the last parameter
> -            const fixedCompareFunction:Function =
> +            const fixedCompareFunction:(values:Object, obj:Object,
> fieldsForCompare?:Array) => int =
>                      function (a:Object, b:Object):int
>                      {
>                          // append our fields to the call, since
> items.sort() won't
>
>

Reply via email to