Stream: compiler development

Topic: crash and abilities


view this post on Zulip Brendan Hansknecht (Jul 09 2024 at 01:05):

I guess you can't always use crash and put in a todo when abilities are involved:

── TYPE MISMATCH in MsgPack.roc ────────────────────────────────────────────────

This specialization of i16 is overly general:

55│  encodeI16 = \_ -> crash "todo"
     ^^^^^^^^^

This value is a declared specialization of type:

    * -> *

But the type annotation on i16 says it must match:

    I16 ->
    FutureEncode.FutureEncoder state where state implements FutureEncode.FutureEncoderFormatting

Note: The specialized type is too general, and does not provide a
concrete type where a type variable is bound to an ability.

Specializations can only be made for concrete types. If you have a
generic implementation for this value, perhaps you don't need an
ability?

Tip: Type comparisons between an opaque type are only ever equal if
both types are the same opaque type. Did you mean to create an opaque
type by wrapping it? If I have an opaque type Age := U32 I can create
an instance of this opaque type by doing @Age 23.

view this post on Zulip Richard Feldman (Jul 09 2024 at 01:12):

hm yeah I'm not sure if that's avoidable :thinking:

view this post on Zulip Brendan Hansknecht (Jul 09 2024 at 01:23):

Luckily, roc is happy turning function prototypes into runtime errors:

encodeI16 : I16 -> FutureEncoder MsgPack

# No definition

view this post on Zulip Richard Feldman (Jul 09 2024 at 01:24):

ha, nice!

view this post on Zulip Brendan Hansknecht (Jul 09 2024 at 01:25):

Trying to make sure that my gist on the new encoders is correct

view this post on Zulip Richard Feldman (Jul 09 2024 at 01:25):

hm, if that's the case, I'm kinda surprised it accepts one but not the other :thinking:

view this post on Zulip Brendan Hansknecht (Jul 09 2024 at 01:25):

Yeah, probably should be printing out a warning with taht

view this post on Zulip Brendan Hansknecht (Jul 09 2024 at 01:25):

it's probably a bug that it just emits a runtime error and no warning

view this post on Zulip Richard Feldman (Jul 09 2024 at 01:25):

@Ayaz Hafiz might know why this works :sweat_smile:

view this post on Zulip Richard Feldman (Jul 09 2024 at 01:26):

I guess it's because in the annotated version it's a less general type

view this post on Zulip Richard Feldman (Jul 09 2024 at 01:26):

but it's still surprising to me that it works

view this post on Zulip Ayaz Hafiz (Jul 09 2024 at 05:03):

yes, that's why

view this post on Zulip Ayaz Hafiz (Jul 09 2024 at 05:03):

the annotation forces the type


Last updated: Jul 06 2025 at 12:14 UTC