Verse - Bug about "false type"

The following code will result in a compile error

func(:any) : false = false
This function returns a value of type false, but the function body's result is an incompatible value of type logic.(3510)

Possible bugs are one of the following

1: It is not a compile error even if “false” is written as the type of the variable.
2: “false” cannot be stored in a variable of type false.

Is " false" a type?
I thought the type was “logic” which can be true/false. So if you change it to

func(:any) : logic = false

That shouldn’t return errors.

1 Like

Thank you very much.
Yes, you are right, the type of the variable should be “logic”.
However, specifying “false” as the type of the variable does not cause a compile error. The error message also says “type false”.
I wanted to know if this is a compiler bug or not.

See also.

1 Like

Thanks for the clarification! That’s interesting to check out indeed :smiley:

1 Like

Apart from being a value of the type logic, false is also a type that has no possible values. As a return type, it indicates that the function doesn’t return a value. The only way to do this right now is using the Err function, which is defined as:

# Halts the Verse runtime with error `Message`.
Err(Message:string)<computes>:false

The reason why it’s valuable to have such a type with no possible values is that it’s a subtype of all other types, also known as the bottom type. You can use a value from :false without regard for what value is expected, and an expression like or or if that joins possible results from different branches into a single type can ignore unreachable branches. For example:

MaybeInt:?int=...
MyInt:int = MaybeInt? or Err("expected MaybeInt to be set")

The left-hand-side of the or yields a value from :int, and the right-hand-side of the or yields a value from :false. This means the combined expression will yield a value from the join :int | :false, but because :false has no possible values this simplifies to :int, and the compiler accepts binding the result to MyInt:int.

3 Likes

I would think that someone in the Reasonable Names department would see that:

  1. The bottom type could simply be “bottom”, and
  2. Having a value and a type with the same name (false and false!) would lead to confusion and is unnecessary.

André