Skip to content

Union Types not working as expected #164

Description

@sstraust

Hi! I'm getting some behavior I can't make sense of:
I defined the following type, which correctly passes type checking when I call it

(t/ann ^:no-check mc/find-one-as-map
(t/U
        [com.mongodb.DB
         (t/Value "eventplanner_tags")
         (t/Map t/Any t/Any)
         ->
         TagType]))

(t/cf (mc/find-one-as-map db "eventplanner_tags" {})) ==> TagType

but adding an additional type to the union causes this to fail:

(t/ann ^:no-check mc/find-one-as-map
       (t/U
        [com.mongodb.DB
         (t/Value "eventplanner_tags")
         (t/Map t/Any t/Any)
         ->
         TagType]
        [com.mongodb.DB
         (t/Value "events2")
         (t/Map t/Any t/Any)
         ->
         EventType]))

(t/cf (mc/find-one-as-map db "eventplanner_tags" {}))  ==> Error

Viewing the error message, it's giving:

Type Error (/Users/sam/sstraust/eventplanner/src/eventplanner/tables.clj:127:7) 
Function mc/find-one-as-map could not be applied to arguments:


Domains:
	com.mongodb.DB (t/Val "events2") (t/Map t/Any t/Any)

Arguments:
	com.mongodb.DB (t/Val "eventplanner_tags") (t/HMap :complete? true)

Ranges:
	eventplanner.tables/EventType

so it looks like adding a second type to the union causes it to not find the first type??

I'm having trouble debugging this/figuring out what's going wrong here

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions