fuzion icon indicating copy to clipboard operation
fuzion copied to clipboard

Confusing error shown when type feature is called with wrong arg count

Open fridis opened this issue 1 year ago • 1 comments

The following code declares a type x and a type feature x.type.y with two arguments, but calls y with three arguments

x.y 1 2 3

x(a,b,c i32) is

  type.y(i,j i32) =>

The error reported, however, complains about x being called with the wrong number of arguments:

 > ./build/bin/fz test_typefeature.fz 

/home/fridi/fuzion/work/test_typefeature.fz:1:1: error 1: Different count of arguments needed when calling feature
x.y 1 2 3
^
Feature not found: 'x' (no arguments)
Target feature: 'universe'
In call: 'x'
To solve this, you might change the actual number of arguments to match the feature 'x' (3 arguments) at /home/fridi/fuzion/work/test_typefeature.fz:3:1:
x(a,b,c i32) is
^

one error.

fridis avatar Jul 09 '24 12:07 fridis

I would argue that, while maybe confusing, this is the error that makes most sense.

See the following example, where it is not possible to tell if y was called with the right number of arguments without knowing which x was intended to be called.

ex is

  x.y 1 2 3

  x(a,b,c i32) is

    type.y(i,j i32) =>

  x(a i32) is

    type.y(i,j,k i32) =>
❯ FUZION_DISABLE_ANSI_ESCAPES=true fz /tmp/test.fz

/tmp/test.fz:3:3: error 1: Different count of arguments needed when calling feature
  x.y 1 2 3
--^
Feature not found: 'x' (no arguments)
Target feature: 'ex'
In call: 'x'
To solve this, you might change the actual number of arguments to match one of the features 'x' (one argument) at /tmp/test.fz:9:3:
  x(a i32) is
--^
, or
'x' (3 arguments) at /tmp/test.fz:5:3:
  x(a,b,c i32) is
--^

one error.

simonvonhackewitz avatar Mar 28 '25 14:03 simonvonhackewitz