avoid Nim 2.0 issue when loading config (#5202)

To avoid Nim 2.0 issue https://github.com/nim-lang/Nim/issues/22284,
explicitly specify `ref SecondarySources` instead of using `auto`,
and add `{.raises.}` annotation
This commit is contained in:
Etan Kissling 2023-07-19 20:26:30 +02:00 committed by GitHub
parent 3eb1729d15
commit da5bb96856
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 3 deletions

View File

@ -201,7 +201,7 @@ template makeBannerAndConfig*(clientId: string, ConfType: type): untyped =
version = version, # but a short version string makes more sense... version = version, # but a short version string makes more sense...
copyrightBanner = clientId, copyrightBanner = clientId,
secondarySources = proc ( secondarySources = proc (
config: ConfType, sources: auto config: ConfType, sources: ref SecondarySources
) {.raises: [ConfigurationError].} = ) {.raises: [ConfigurationError].} =
if config.configFile.isSome: if config.configFile.isSome:
sources.addConfigFile(Toml, config.configFile.get) sources.addConfigFile(Toml, config.configFile.get)

View File

@ -82,6 +82,8 @@ proc main(flags: CliFlags) {.async.} =
waitFor main( waitFor main(
load(CliFlags, load(CliFlags,
secondarySources = proc (config: CliFlags, sources: auto) = secondarySources = proc (
config: CliFlags, sources: ref SecondarySources
) {.raises: [ConfigurationError].} =
if config.configFile.isSome: if config.configFile.isSome:
sources.addConfigFile(Toml, config.configFile.get))) sources.addConfigFile(Toml, config.configFile.get)))

View File

@ -21,7 +21,9 @@ type
proc loadExampleConfig(content: string, cmdLine = newSeq[string]()): ExampleConfigFile = proc loadExampleConfig(content: string, cmdLine = newSeq[string]()): ExampleConfigFile =
ExampleConfigFile.load( ExampleConfigFile.load(
cmdLine = cmdLine, cmdLine = cmdLine,
secondarySources = proc (config: ExampleConfigFile, sources: auto) = secondarySources = proc (
config: ExampleConfigFile, sources: ref SecondarySources
) {.raises: [ConfigurationError].} =
sources.addConfigFileContent(Toml, content)) sources.addConfigFileContent(Toml, content))
const const