首页 > 解决方案 > 错误:没有重载匹配类型为 (Array(String) | Nil) 的“Log::Context.new”

问题描述

我确实通过官方 docker 镜像更新到 Crystal 0.35.1。不幸的是,我的项目在水晶本身的某个地方出现编译错误错误:没有重载匹配类型为 (Array(String) | Nil) 的“Log::Context.new”。

root@395e51d80ee6:/app# crystal spec --error-trace
In /usr/share/crystal/src/log/entry.cr:43:35

 43 | getter context : Metadata = Log.context.metadata
                                      ^------
Error: instantiating 'Log.class#context()'


In /usr/share/crystal/src/log/main.cr:56:18

 56 | Log::Context.new(Fiber.current.logging_context)
                   ^--
Error: no overload matches 'Log::Context.new' with type (Array(String) | Nil)

Overloads are:
 - Log::Context.new(metadata : Metadata)

Nil trace:

  /usr/share/crystal/src/log/main.cr:56

        Log::Context.new(Fiber.current.logging_context)
                                       ^~~~~~~~~~~~~~~

  macro property (in expanded macro: macro_140471448844816:630):6

                def logging_context : Array(String) | ::Nil
                    ^~~~~~~~~~~~~~~

  macro property (in expanded macro: macro_140471448844816:630):7

                  @logging_context


  macro property (in expanded macro: macro_140471448844816:630):4

                @logging_context : Array(String) | ::Nil

我的水晶版是

croot@395e51d80ee6:/app# crystal -v
Crystal 0.35.1 [5999ae29b] (2020-06-19)

LLVM: 8.0.0
Default target: x86_64-unknown-linux-gnu

标签: crystal-lang

解决方案


我的编译被破坏了require "sidekiq"(看起来碎片不再维护),我切换到require "mosquito". IMO Crystal 编译器应在回溯中显示问题的直接根源。


推荐阅读