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

some typeclasses don't work with typed, macros.symBodyHash crashes with ptr, ref #17733

Open
timotheecour opened this issue Apr 15, 2021 · 0 comments

Comments

@timotheecour
Copy link
Member

Example

when true:
  import std/macros

  macro repr2(s: typed): string = 
    result = newLit(s.repr)

  macro symHash(s: typed): string = 
    result = newLit(symBodyHash(s))

  type A[T] = object
    x: T

  proc fn1(x: seq) = discard
  proc fn2(x: ref) = discard
  proc fn2b(x: ptr) = discard
  proc fn3(x: pointer | ref | ptr) = discard
  proc fn4(x: A) = discard

  proc fn0(x: pointer) = discard
  proc fn5[T](x: A[T]) = discard
  proc fn6(x: tuple) = discard
  proc fn7(x: pointer | tuple) = discard

  # ok
  discard symHash(fn0)
  discard symHash(fn5)
  discard symHash(fn6)
  discard symHash(fn7)

  # ok
  discard repr2(fn2)
  discard repr2(fn2b)
  discard repr2(fn3)

  # BUG D20210415T162824: Error: 'fn4' doesn't have a concrete type, due to unspecified generic parameters.
  # discard symHash(fn4)
  # discard symHash(fn1) # ditto

  # BUG D20210415T162832: Error: unhandled exception: index out of bounds, the container is empty [IndexDefect]
  # discard symHash(fn3)
  # discard symHash(fn2) # ditto
  # discard symHash(fn2b) # ditto

#[
/Users/timothee/git_clone/nim/Nim_prs/compiler/semexprs.nim(2793) semExpr /Users/timothee/git_clone/nim/timn/tests/nim/all/t12171.nim(50, 18) nkCall
/Users/timothee/git_clone/nim/Nim_prs/compiler/semexprs.nim(1037) semDirectOp
/Users/timothee/git_clone/nim/Nim_prs/compiler/semexprs.nim(919) afterCallActions
/Users/timothee/git_clone/nim/Nim_prs/compiler/sem.nim(472) semMacroExpr
/Users/timothee/git_clone/nim/Nim_prs/compiler/vm.nim(2330) evalMacroCall
/Users/timothee/git_clone/nim/Nim_prs/compiler/vm.nim(1213) rawExecute
/Users/timothee/git_clone/nim/Nim_prs/compiler/vmops.nim(242) :anonymous
/Users/timothee/git_clone/nim/Nim_prs/compiler/sighashes.nim(378) symBodyDigest
/Users/timothee/git_clone/nim/Nim_prs/compiler/sighashes.nim(221) hashType
/Users/timothee/git_clone/nim/Nim_prs/compiler/sighashes.nim(240) hashType
/Users/timothee/git_clone/nim/Nim_prs/compiler/sighashes.nim(240) hashType
/Users/timothee/git_clone/nim/Nim_prs/compiler/sighashes.nim(186) hashType
/Users/timothee/git_clone/nim/Nim_prs/compiler/ast.nim(1342) lastSon
/Users/timothee/git_clone/nim/Nim_prs/lib/system.nim(2647) []
/Users/timothee/git_clone/nim/Nim_prs/lib/system/fatal.nim(53) sysFatal
Error: unhandled exception: index out of bounds, the container is empty [IndexDefect]

]#

Current Output

uncomment discard symHash(fn4):
Error: 'fn4' doesn't have a concrete type, due to unspecified generic parameters.

uncomment discard symHash(fn3):
Error: unhandled exception: index out of bounds, the container is empty [IndexDefect]

Expected Output

these should all work

  • both fn5 and fn4 should be typed (a typeclass should be valid)
  • there's no reason proc fn(a: ref) should be typed but not proc fn(a: seq) (etc)
  • the crash with fn3 shouldn't happen

Additional Information

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

No branches or pull requests

1 participant