diff --git a/compiler/linter.nim b/compiler/linter.nim index a80c377e95..b8358f5de9 100644 --- a/compiler/linter.nim +++ b/compiler/linter.nim @@ -12,7 +12,7 @@ import std/strutils from std/sugar import dup -import options, ast, msgs, idents, lineinfos, wordrecg, astmsgs, semdata, packages +import options, ast, msgs, idents, lineinfos, wordrecg, astmsgs, semdata, packages, modulegraphs export packages const @@ -97,7 +97,7 @@ template styleCheckDef*(ctx: PContext; info: TLineInfo; sym: PSym; k: TSymKind) if optStyleCheck in ctx.config.options and # ignore if styleChecks are off {optStyleHint, optStyleError} * ctx.config.globalOptions != {} and # check only if hint/error is enabled hintName in ctx.config.notes and # ignore if name checks are not requested - ctx.config.belongsToProjectPackage(sym) and # ignore foreign packages + ctx.config.belongsToProjectPackageMaybeNil(getModule(ctx.graph, info.fileIndex)) and # ignore foreign packages optStyleUsages notin ctx.config.globalOptions and # ignore if requested to only check name usage sym.kind != skResult and # ignore `result` sym.kind != skTemp and # ignore temporary variables created by the compiler @@ -138,7 +138,7 @@ template styleCheckUse*(ctx: PContext; info: TLineInfo; sym: PSym) = ## Check symbol uses match their definition's style. if {optStyleHint, optStyleError} * ctx.config.globalOptions != {} and # ignore if styleChecks are off hintName in ctx.config.notes and # ignore if name checks are not requested - ctx.config.belongsToProjectPackage(sym) and # ignore foreign packages + ctx.config.belongsToProjectPackageMaybeNil(getModule(ctx.graph, info.fileIndex)) and # ignore foreign packages sym.kind != skTemp and # ignore temporary variables created by the compiler sym.name.s[0] in Letters and # ignore operators TODO: what about unicode symbols??? sfAnon notin sym.flags: # ignore temporary variables created by the compiler @@ -154,5 +154,5 @@ template checkPragmaUse*(ctx: PContext; info: TLineInfo; w: TSpecialWord; pragma ## Note: This only applies to builtin pragmas, not user pragmas. if {optStyleHint, optStyleError} * ctx.config.globalOptions != {} and # ignore if styleChecks are off hintName in ctx.config.notes and # ignore if name checks are not requested - (sym != nil and ctx.config.belongsToProjectPackage(sym)): # ignore foreign packages + ctx.config.belongsToProjectPackageMaybeNil(getModule(ctx.graph, info.fileIndex)): # ignore foreign packages checkPragmaUseImpl(ctx.config, info, w, pragmaName) diff --git a/compiler/packages.nim b/compiler/packages.nim index bb54d61546..63879acd26 100644 --- a/compiler/packages.nim +++ b/compiler/packages.nim @@ -51,3 +51,11 @@ func belongsToProjectPackage*(conf: ConfigRef, sym: PSym): bool = ## See Also: ## * `modulegraphs.belongsToStdlib` conf.mainPackageId == sym.getPackageId + +func belongsToProjectPackageMaybeNil*(conf: ConfigRef, sym: PSym): bool = + ## Return whether the symbol belongs to the project's package. + ## Returns `false` if `sym` is nil. + ## + ## See Also: + ## * `modulegraphs.belongsToStdlib` + sym != nil and conf.mainPackageId == sym.getPackageId diff --git a/tests/stdlib/tdeques.nim b/tests/stdlib/tdeques.nim index 39ff996d11..b8eca55e96 100644 --- a/tests/stdlib/tdeques.nim +++ b/tests/stdlib/tdeques.nim @@ -224,7 +224,7 @@ proc main() = block: var a, b = initDeque[int]() - for i in countDown(100, 1): + for i in countdown(100, 1): a.addFirst(i) for i in 1..100: b.addLast(i) diff --git a/tests/stylecheck/tforeign_package.nim b/tests/stylecheck/tforeign_package.nim index 8594ad802e..eb55851398 100644 --- a/tests/stylecheck/tforeign_package.nim +++ b/tests/stylecheck/tforeign_package.nim @@ -13,4 +13,13 @@ import foreign_package/foreign_package # - user pragma usage violations # - definition violations in foreign packages are ignored # - usage violations in foreign packages are ignored -genericProc[int]() +generic_proc[int]() +# issue #24269, stdlib: +proc c(_: openArray[int]) = discard +static: + doAssert compiles(generic_proc[int]()) + doAssert not compiles(genericProc[int]()) + doAssert not (compiles do: + proc c(_: openarray[int]) = discard) + doAssert (compiles do: + proc d(_: openArray[int]) = discard)