Skip to content

Error: generic instantiation too nested #17

Description

@gabbhack

During some work on new version of deser and deser_json I found that the code below doesn't compile

Code below
import options

import deser, deser_json

let jsonString = readFile("twitter.json")

type
  Object = object
    statuses: seq[Status]
    search_metadata: SearchMetadata

  Status = object
    metadata: Metadata
    created_at: string
    id: int64
    id_str: string
    text: string
    source: string
    truncated: bool
    in_reply_to_status_id: Option[float]
    in_reply_to_status_id_str: Option[string]
    in_reply_to_user_id: Option[int]
    in_reply_to_user_id_str: Option[string]
    in_reply_to_screen_name: Option[string]
    user: User
    retweet_count: int64
    favorite_count: int64
    entities: StatusEntities
    favorited: bool
    retweeted: bool
    lang: string

  Metadata = object
    result_type: string
    iso_language_code: string

  User = object
    id: int
    id_str: string
    name: string
    screen_name: string
    location: string
    description: string
    url: Option[string]
    entities: UserEntities
    protected: bool
    followers_count: int64
    friends_count: int64
    listed_count: int64
    created_at: string
    favourites_count: int64
    utc_offset: Option[int]
    time_zone: Option[string]
    geo_enabled: bool
    verified: bool
    statuses_count: int64
    lang: string
    contributors_enabled: bool
    is_translator: bool
    is_translation_enabled: bool
    profile_background_color: string
    profile_background_image_url: string
    profile_background_image_url_https: string
    profile_background_tile: bool
    profile_image_url: string
    profile_image_url_https: string
    profile_banner_url: Option[string]
    profile_link_color: string
    profile_sidebar_border_color: string
    profile_sidebar_fill_color: string
    profile_text_color: string
    profile_use_background_image: bool
    default_profile: bool
    default_profile_image: bool
    following: bool
    follow_request_sent: bool
    notifications: bool

  UserEntities = object
    description: Description
    url: Option[Description]

  Description = object
    urls: seq[Url]

  Url = object
    url: string
    expanded_url: string
    display_url: string
    indices: seq[int64]

  StatusEntities = object
    hashtags: seq[Hashtag]
    urls: seq[Url]
    user_mentions: seq[UserMentions]
    media: Option[seq[Media]]
  
  Hashtag = object
    text: string
    indices: seq[int]
  
  Media = object
    id: int64
    id_str: string
    indices: seq[int64]
    media_url: string
    media_url_https: string
    url: string
    display_url: string
    expanded_url: string
    `type`: string
    sizes: Sizes
    source_status_id: Option[float]
    source_status_id_str: Option[string]
  
  Sizes = object
    thumb: Size
    large: Size
    medium: Size
    small: Size
  
  Size = object
    w: int64
    h: int64
    resize: string

  UserMentions = object
    screen_name: string
    name: string
    id: int64
    id_str: string
    indices: seq[int64]

  SearchMetadata = object
    completed_in: float64
    max_id: int64
    max_id_str: string
    next_results: string
    query: string
    refresh_url: string
    count: int64
    since_id: int64
    since_id_str: string

makeDeserializable([
  Object,
  Status,
  Metadata,
  User,
  UserEntities,
  Description,
  Url,
  StatusEntities,
  Hashtag,
  Media,
  Sizes,
  Size,
  UserMentions,
  SearchMetadata
])

for i in 0..1000000:
  var obj = fromJson(Object, jsonString)
Error
C:\Users\Noname\Desktop\main.nim(163, 21) template/generic instantiation of `fromJson` from here
E:\Dev\nim\deser_json\src\deser_json\des.nim(22, 7) template/generic instantiation of `deserialize` from here
C:\Users\Noname\Desktop\main.nim(146, 3) template/generic instantiation of `deserializeMap` from here
E:\Dev\nim\deser_json\src\deser_json\des\des.nim(201, 19) template/generic instantiation of `visitMap` from here
C:\Users\Noname\Desktop\main.nim(146, 3) template/generic instantiation of `nextValue` from here
E:\Dev\nim\deser\src\deser\des\helpers.nim(399, 11) template/generic instantiation of `nextValueSeed` from here
E:\Dev\nim\deser_json\src\deser_json\des\des.nim(251, 7) template/generic instantiation of `deserialize` from here
E:\Dev\nim\deser\src\deser\des\impls.nim(41, 13) template/generic instantiation of `deserialize` from here
E:\Dev\nim\deser\src\deser\des\impls.nim(275, 15) template/generic instantiation of `deserializeSeq` from here
E:\Dev\nim\deser_json\src\deser_json\des\des.nim(193, 19) template/generic instantiation of `visitSeq` from here
E:\Dev\nim\deser\src\deser\des\impls.nim(268, 23) template/generic instantiation of `items` from here
E:\Dev\nim\deser\src\deser\des\helpers.nim(353, 45) template/generic instantiation of `nextElement` from here
E:\Dev\nim\deser\src\deser\des\helpers.nim(348, 11) template/generic instantiation of `nextElementSeed` from here
E:\Dev\nim\deser_json\src\deser_json\des\des.nim(231, 14) template/generic instantiation of `deserialize` from here
E:\Dev\nim\deser\src\deser\des\impls.nim(41, 13) template/generic instantiation of `deserialize` from here
C:\Users\Noname\Desktop\main.nim(147, 3) template/generic instantiation of `deserializeMap` from here
E:\Dev\nim\deser_json\src\deser_json\des\des.nim(201, 19) template/generic instantiation of `visitMap` from here
C:\Users\Noname\Desktop\main.nim(147, 3) template/generic instantiation of `nextValue` from here
E:\Dev\nim\deser\src\deser\des\helpers.nim(399, 11) template/generic instantiation of `nextValueSeed` from here
E:\Dev\nim\deser_json\src\deser_json\des\des.nim(251, 7) template/generic instantiation of `deserialize` from here
E:\Dev\nim\deser\src\deser\des\impls.nim(41, 13) template/generic instantiation of `deserialize` from here
C:\Users\Noname\Desktop\main.nim(149, 3) template/generic instantiation of `deserializeMap` from here
E:\Dev\nim\deser_json\src\deser_json\des\des.nim(201, 19) template/generic instantiation of `visitMap` from here
C:\Users\Noname\Desktop\main.nim(149, 3) template/generic instantiation of `nextValue` from here
E:\Dev\nim\deser\src\deser\des\helpers.nim(399, 11) template/generic instantiation of `nextValueSeed` from here
E:\Dev\nim\deser_json\src\deser_json\des\des.nim(251, 7) template/generic instantiation of `deserialize` from here
E:\Dev\nim\deser\src\deser\des\impls.nim(41, 13) template/generic instantiation of `deserialize` from here
C:\Users\Noname\Desktop\main.nim(150, 3) template/generic instantiation of `deserializeMap` from here
E:\Dev\nim\deser_json\src\deser_json\des\des.nim(201, 19) template/generic instantiation of `visitMap` from here
C:\Users\Noname\Desktop\main.nim(150, 3) template/generic instantiation of `nextValue` from here
E:\Dev\nim\deser\src\deser\des\helpers.nim(399, 11) template/generic instantiation of `nextValueSeed` from here
E:\Dev\nim\deser_json\src\deser_json\des\des.nim(251, 7) template/generic instantiation of `deserialize` from here
E:\Dev\nim\deser\src\deser\des\impls.nim(41, 13) template/generic instantiation of `deserialize` from here
C:\Users\Noname\Desktop\main.nim(151, 3) template/generic instantiation of `deserializeMap` from here
E:\Dev\nim\deser_json\src\deser_json\des\des.nim(201, 19) template/generic instantiation of `visitMap` from here
C:\Users\Noname\Desktop\main.nim(151, 3) template/generic instantiation of `nextValue` from here
E:\Dev\nim\deser\src\deser\des\helpers.nim(399, 11) template/generic instantiation of `nextValueSeed` from here
E:\Dev\nim\deser_json\src\deser_json\des\des.nim(251, 7) template/generic instantiation of `deserialize` from here
E:\Dev\nim\deser\src\deser\des\impls.nim(41, 13) template/generic instantiation of `deserialize` from here
E:\Dev\nim\deser\src\deser\des\impls.nim(275, 15) template/generic instantiation of `deserializeSeq` from here
E:\Dev\nim\deser_json\src\deser_json\des\des.nim(193, 19) template/generic instantiation of `visitSeq` from here
E:\Dev\nim\deser\src\deser\des\impls.nim(268, 23) template/generic instantiation of `items` from here
E:\Dev\nim\deser\src\deser\des\helpers.nim(353, 45) template/generic instantiation of `nextElement` from here
E:\Dev\nim\deser\src\deser\des\helpers.nim(348, 11) template/generic instantiation of `nextElementSeed` from here
E:\Dev\nim\deser_json\src\deser_json\des\des.nim(231, 14) template/generic instantiation of `deserialize` from here
E:\Dev\nim\deser\src\deser\des\impls.nim(41, 13) template/generic instantiation of `deserialize` from here
C:\Users\Noname\Desktop\main.nim(152, 3) template/generic instantiation of `deserializeMap` from here
E:\Dev\nim\deser_json\src\deser_json\des\des.nim(201, 19) template/generic instantiation of `visitMap` from here
C:\Users\Noname\Desktop\main.nim(152, 3) template/generic instantiation of `keys` from here
E:\Dev\nim\deser\src\deser\des\helpers.nim(408, 35) template/generic instantiation of `nextKey` from here
E:\Dev\nim\deser\src\deser\des\helpers.nim(396, 11) template/generic instantiation of `nextKeySeed` from here
E:\Dev\nim\deser_json\src\deser_json\des\des.nim(236, 22) template/generic instantiation of `eatSpace` from here
E:\Dev\nim\deser_json\src\deser_json\jsony.nim(52, 10) Error: generic instantiation too nested

After recompile compiler with higher c.instCounter value error was fixed

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

    bugSomething isn't workingnim worksSomething is not working because of a bug in the language

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions