fuzion icon indicating copy to clipboard operation
fuzion copied to clipboard

Used abstract feature is not implemented, but I think it is?

Open michaellilltokiwa opened this issue 3 years ago • 2 comments

This example:

ex =>

  seq(T type) ref is

  str(U type) ref : seq U is

    a U is abstract

    b(V type, c V) str V is
      ref : str V
        redef a V is
          c

  say ((str string).b "hello").a

yields:

/home/sam/playground/test.fz:5:3: error 1: Used abstract feature a is not implemented
  str(U type) ref : seq U is
--^
Feature 'ex.str' instantiated at /home/sam/playground/test.fz:14:9:
  s := (str string)
--------^
inherits or declares abstract feature 'ex.str.a' declared at /home/sam/playground/test.fz:7:5:
    a U is abstract
----^
which is called at /home/sam/playground/test.fz:15:20:
  say s.b("hello").a
-------------------^
without providing an implementation

one error.

michaellilltokiwa avatar Aug 04 '22 14:08 michaellilltokiwa

Updated the example

ex =>

  seq(T type) ref is

  str(U type) ref : seq U is

    a U is abstract

    b(V type, c V) str V is
      ref : str V
        redef a V is
          c

  say ((str String).b "hello").a

This shows two errors now

● fridi@zen:~/fuzion/work 11:34:06 > PRECONDITIONS=true POSTCONDITIONS=true ./build/bin/fz ex373.fz

/home/fridi/fuzion/work/ex373.fz:9:5: error 1: Recursive value type is not allowed
    b(V type, c V) str V is
----^
Value type (ex.str String).b String equals type of outer feature.
The chain of outer types that lead to this recursion is:
1: (ex.str String).b String at /home/fridi/fuzion/work/ex373.fz:9:5:
    b(V type, c V) str V is
----^
2: ((ex.str String).b String).#anonymous0 at /home/fridi/fuzion/work/ex373.fz:10:7:
      ref : str V
------^
3: (ex.str String).b String at /home/fridi/fuzion/work/ex373.fz:9:5:
    b(V type, c V) str V is
----^

To solve this, you could add a 'ref' after the arguments list at /home/fridi/fuzion/work/ex373.fz:9:5:
    b(V type, c V) str V is
----^


/home/fridi/fuzion/work/ex373.fz:5:3: error 2: Used abstract feature 'ex.str.a' is not implemented by 'ex.str'
  str(U type) ref : seq U is
--^
Feature 'ex.str' instantiated at /home/fridi/fuzion/work/ex373.fz:14:9:
  say ((str String).b "hello").a
--------^
inherits or declares abstract feature 'ex.str.a' declared at /home/fridi/fuzion/work/ex373.fz:7:5:
    a U is abstract
----^
which is called at /home/fridi/fuzion/work/ex373.fz:14:32:
  say ((str String).b "hello").a
-------------------------------^
without providing an implementation

2 errors.

The problems with these two errors

  • the first one is maybe justified, but confusing: The anonymous inner feature ref: str is the problem, its outer feature is b, which itself is defined in str, so we could call b within the anonymous inner feature causing and endless chain nested bs (but this might be ok since the inner feature is a ref).
  • the second error is obviously wrong.

fridis avatar May 15 '23 09:05 fridis

update example:

ex =>

  str(U type) ref is

    a U => abstract

    b(V type, c V) str V =>
      ref : str V
        redef a V =>
          c

  say ((str String).b "hello").a

michaellilltokiwa avatar May 14 '24 07:05 michaellilltokiwa