Skip to content

fix sigmatch: can't infer constrained generic params#25871

Open
Graveflo wants to merge 3 commits into
nim-lang:develfrom
Graveflo:ovrl_inst_nil
Open

fix sigmatch: can't infer constrained generic params#25871
Graveflo wants to merge 3 commits into
nim-lang:develfrom
Graveflo:ovrl_inst_nil

Conversation

@Graveflo

@Graveflo Graveflo commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

test self-explanatory

@Graveflo

Graveflo commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

this looks like a chronos bug. The test is meant to attempt matching openArray[SomeFuture] but it matches openArray[FutureBase]. The compiles assertion passed before because of this error leakage.

Comment thread compiler/sigmatch.nim Outdated
f: PType): PType =
result = lookup(m.bindings, f)
if result == nil:
let oldErrorCounter = c.config.errorCounter

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does it try to instantiate a generic with an unsufficient number of inferred typevars? This fix doesn't attack the root cause.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point

@Graveflo Graveflo marked this pull request as draft June 5, 2026 04:32
@Graveflo Graveflo marked this pull request as ready for review June 5, 2026 20:19
@Graveflo Graveflo force-pushed the ovrl_inst_nil branch 2 times, most recently from a07a71b to 35b4b54 Compare June 9, 2026 15:22
Comment thread compiler/sigmatch.nim Outdated
internalError(c.graph.config, arg.info, "getInstantiatedType")
result = errorType(c)
if allParamsBound(m.bindings, f):
result = generateTypeInstance(c, m.bindings, arg, f)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead make generateTypeInstance return nil on missing type-variables and don't produce an internalError for it.

@Graveflo Graveflo Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would require digging all the way into lookupTypeVar and replaceTypeVarsTAux which can be mitigated with a flag, but also semAfterMacroCall inferWithMetatype and instantiateGenericParamList use generateTypeInstance as well and would have their error behavior changed. In order for generateTypeInstance to return nil instead of erroring the error paths have to be disabled for all of these calls which either loses granularity on which error happened, forces a second error-enabled path like sigmatch does, or just generally makes it confusing what to return and what side effects to expect since the error paths got disabled.
I can understand not wanting to do the pre-pass if it can be avoided, but I'm not sure how to do that cleanly. Maybe I'm just on the wrong track?
(edit: wait, I can just make generateTypeInstance take a boolean... let me try that)

Comment thread compiler/sigmatch.nim Outdated
var m = newCandidate(c, f)
result = typeRel(m, f, a)

proc allParamsBound(bindings: LayeredIdTable, t: PType): bool =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should fall out naturally for a properly coded generateTypeInstance.

@Graveflo

Graveflo commented Jun 13, 2026

Copy link
Copy Markdown
Contributor Author

pretty sure this is a runner error and not the patch.

Looks like there are 3 (maybe 4?) methods for fixing this:

  1. error trap
  2. pre-scan
  3. semtypinst.nim conditional error muting (current)
  4. might be able to do a post scan with allowMetaTypes and containsGenericType

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants