Skip to content

can't infer the type of instance variable '@expires_in' of Cache::Store(String, String) #38

@zw963

Description

@zw963

reproduce:

require "./src/cache"

CACHE_STORE = if true
                Cache::MemoryStore(String, String)
              else
                Cache::NullStore(String, String)
              end

MARKDOWN_CACHE = CACHE_STORE.new(expires_in: 1.minutes)

MARKDOWN_CACHE.fetch("foo") { "foo" }

Get error like following:

Showing last frame. Use --error-trace for full trace.

In src/cache/store.cr:35:40

 35 | def fetch(key : K, *, expires_in = @expires_in, &)
                                         ^----------
Error: can't infer the type of instance variable '@expires_in' of Cache::Store(String, String)

Could you add a type annotation like this

    struct Cache::Store(String, String)
      @expires_in : Type
    end

replacing `Type` with the expected type of `@expires_in`?

Thanks

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