Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad error message when returning object with missing generic #24372

Closed
ire4ever1190 opened this issue Oct 28, 2024 · 3 comments · Fixed by #24455
Closed

Bad error message when returning object with missing generic #24372

ire4ever1190 opened this issue Oct 28, 2024 · 3 comments · Fixed by #24455

Comments

@ire4ever1190
Copy link
Contributor

ire4ever1190 commented Oct 28, 2024

Description

This code passes nim check but then fails to compile. Previously it returned an error when checking.

type
  Foo[T] = object
    x: string
    
proc initFoo(): Foo[string] =
  Foo(x: "hello")

discard initFoo()

Nim Version

Nim Compiler Version 2.2.1 [Linux: amd64]
Compiled at 2024-10-27
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: 24aa92c
active boot switches: -d:release

Current Output

nim.nim                  nim
nim.nim                  handleCmdLine
main.nim                 mainCommand
main.nim                 compileToBackend
main.nim                 commandCompileToC
pipelines.nim            compilePipelineProject
pipelines.nim            compilePipelineModule
pipelines.nim            processPipelineModule
pipelines.nim            processPipeline
cgen.nim                 genTopLevelStmt
cgen.nim                 genProcBody
ccgstmts.nim             genStmts
ccgexprs.nim             expr /home/jake/Documents/projects/Nim/x.nim(3, 3) nkStmtList
ccgexprs.nim             genStmtList
ccgstmts.nim             genStmts
ccgexprs.nim             expr /home/jake/Documents/projects/Nim/x.nim(3, 3) nkStmtList
ccgexprs.nim             genStmtList
ccgstmts.nim             genStmts
ccgexprs.nim             expr /home/jake/Documents/projects/Nim/x.nim(9, 1) nkDiscardStmt
cgen.nim                 initLocExprSingleUse
ccgexprs.nim             expr /home/jake/Documents/projects/Nim/x.nim(9, 16) nkStmtListExpr
ccgexprs.nim             genStmtListExpr
ccgstmts.nim             genStmts
ccgexprs.nim             expr /home/jake/Documents/projects/Nim/x.nim(9, 16) nkFastAsgn
ccgstmts.nim             genAsgn
ccgstmts.nim             loadInto
ccgcalls.nim             genAsgnCall
ccgcalls.nim             genPrefixCall
cgen.nim                 initLocExpr
ccgexprs.nim             expr /home/jake/Documents/projects/Nim/x.nim(9, 9) nkSym
cgen.nim                 genProc
cgen.nim                 genProcNoForward
cgen.nim                 genProcAux
injectdestructors.nim    injectDestructorCalls
injectdestructors.nim    p
injectdestructors.nim    moveOrCopy
injectdestructors.nim    p
types.nim                lookupFieldAgain
assertions.nim           failedAssertImpl
assertions.nim           raiseAssert
Error: unhandled exception: types.nim(1916, 11) `ty.kind in {tyTuple, tyObject}`  [AssertionDefect]

Expected Output

Either the previous message

Error: type mismatch: got 'Foo' for 'Foo(x: "hello")' but expected 'Foo[system.string]'

Or have the generic inferred

Known Workarounds

No response

Additional Information

Fails with --mm:refc also, but in ccgexprs.nim

@ringabout
Copy link
Member

!nim c

type
  Foo[T] = object
    x: string
    
proc initFoo(): Foo[string] =
  Foo(x: "hello")

discard initFoo()

Copy link
Contributor

🐧 Linux bisect by @ringabout (member)
devel 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-10-28T11:27:57
  • Finished 2024-10-28T11:27:57
  • Duration

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Foo"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("T"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("x"),
            newIdentNode("string"),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("initFoo"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Foo"),
        newIdentNode("string")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkObjConstr.newTree(
        newIdentNode("Foo"),
        nnkExprColonExpr.newTree(
          newIdentNode("x"),
          newLit("hello")
        )
      )
    )
  ),
  nnkDiscardStmt.newTree(
    nnkCall.newTree(
      newIdentNode("initFoo")
    )
  )
)
stable 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-10-28T11:28:00
  • Finished 2024-10-28T11:28:01
  • Duration

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Foo"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("T"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("x"),
            newIdentNode("string"),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("initFoo"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Foo"),
        newIdentNode("string")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkObjConstr.newTree(
        newIdentNode("Foo"),
        nnkExprColonExpr.newTree(
          newIdentNode("x"),
          newLit("hello")
        )
      )
    )
  ),
  nnkDiscardStmt.newTree(
    nnkCall.newTree(
      newIdentNode("initFoo")
    )
  )
)
2.0.10 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-10-28T11:28:04
  • Finished 2024-10-28T11:28:04
  • Duration

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Foo"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("T"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("x"),
            newIdentNode("string"),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("initFoo"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Foo"),
        newIdentNode("string")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkObjConstr.newTree(
        newIdentNode("Foo"),
        nnkExprColonExpr.newTree(
          newIdentNode("x"),
          newLit("hello")
        )
      )
    )
  ),
  nnkDiscardStmt.newTree(
    nnkCall.newTree(
      newIdentNode("initFoo")
    )
  )
)
2.0.0 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-10-28T11:28:07
  • Finished 2024-10-28T11:28:07
  • Duration

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Foo"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("T"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("x"),
            newIdentNode("string"),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("initFoo"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Foo"),
        newIdentNode("string")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkObjConstr.newTree(
        newIdentNode("Foo"),
        nnkExprColonExpr.newTree(
          newIdentNode("x"),
          newLit("hello")
        )
      )
    )
  ),
  nnkDiscardStmt.newTree(
    nnkCall.newTree(
      newIdentNode("initFoo")
    )
  )
)
1.6.20 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-10-28T11:28:10
  • Finished 2024-10-28T11:28:10
  • Duration

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Foo"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("T"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("x"),
            newIdentNode("string"),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("initFoo"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Foo"),
        newIdentNode("string")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkObjConstr.newTree(
        newIdentNode("Foo"),
        nnkExprColonExpr.newTree(
          newIdentNode("x"),
          newLit("hello")
        )
      )
    )
  ),
  nnkDiscardStmt.newTree(
    nnkCall.newTree(
      newIdentNode("initFoo")
    )
  )
)
1.4.8 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-10-28T11:28:12
  • Finished 2024-10-28T11:28:12
  • Duration

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Foo"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("T"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("x"),
            newIdentNode("string"),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("initFoo"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Foo"),
        newIdentNode("string")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkObjConstr.newTree(
        newIdentNode("Foo"),
        nnkExprColonExpr.newTree(
          newIdentNode("x"),
          newLit("hello")
        )
      )
    )
  ),
  nnkDiscardStmt.newTree(
    nnkCall.newTree(
      newIdentNode("initFoo")
    )
  )
)
1.2.18 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-10-28T11:28:15
  • Finished 2024-10-28T11:28:15
  • Duration

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Foo"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("T"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("x"),
            newIdentNode("string"),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("initFoo"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Foo"),
        newIdentNode("string")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkObjConstr.newTree(
        newIdentNode("Foo"),
        nnkExprColonExpr.newTree(
          newIdentNode("x"),
          newLit("hello")
        )
      )
    )
  ),
  nnkDiscardStmt.newTree(
    nnkCall.newTree(
      newIdentNode("initFoo")
    )
  )
)
1.0.10 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-10-28T11:28:17
  • Finished 2024-10-28T11:28:17
  • Duration

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Foo"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("T"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("x"),
            newIdentNode("string"),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("initFoo"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Foo"),
        newIdentNode("string")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkObjConstr.newTree(
        newIdentNode("Foo"),
        nnkExprColonExpr.newTree(
          newIdentNode("x"),
          newLit("hello")
        )
      )
    )
  ),
  nnkDiscardStmt.newTree(
    nnkCall.newTree(
      newIdentNode("initFoo")
    )
  )
)
Stats
  • GCC 11.4.0
  • Clang 14.0.0
  • NodeJS 20.4
  • Created 2024-10-28T11:27:29Z
  • Comments 1
  • Commands nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim

🤖 Bug found in 23 mins bisecting 8 commits at 0 commits per second

@metagn
Copy link
Collaborator

metagn commented Nov 19, 2024

Correct error message in devel now? Weird

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

Successfully merging a pull request may close this issue.

3 participants