fuzion icon indicating copy to clipboard operation
fuzion copied to clipboard

define type feature in type feature should raise an error?

Open michaellilltokiwa opened this issue 1 year ago • 2 comments

I think this should not be allowed but currently does not raise an error?

ex is

  type.one is
    type.two is // should be an error
      say "hello"

neither should this:

ex is

  type.one is
    b is
      type.two is // should be an error
        say "hello"

defining type feature in anonymous feature should probably also be an error:

ex is
  ref : String
    type.two is // should be an error
      say "hello"

This raises an error but a very weird one:

ex is
  [1].map i->
    type.one => 1
    unit
/home/sam/playground/test.fz:3:11: error 1: Incompatible type parameter
  [1].map i->
----------^^^
    type.one => 1
^^^^^^^^^^^^^^^^^
    unit
^^^^^^^^
formal type parameter 'T' with constraint 'Any'
actual type parameter 'universe'

one error.

michaellilltokiwa avatar Mar 25 '24 09:03 michaellilltokiwa

Yes, this still needs to be checked, and probably forbidden. Since the outer feature of a type feature o.f.type is the type feature of the outer feature o.type, and we do not want recursive type features, the outer feature must never be a type feature.

fridis avatar Mar 25 '24 12:03 fridis

The type of a type is just Type:

 > ./build/bin/fz -e "say (type_of 1)"
Type of 'i32'
 > ./build/bin/fz -e "say (type_of (type_of 1))"
Type of 'Type'
 > ./build/bin/fz -e "say (type_of (type_of (type_of 1)))"
Type of 'Type'

so we could also allow outer features to be type feature, but then the type-types are just Type.type... Need to check if this make sense in any context.

fridis avatar Mar 25 '24 13:03 fridis