tproc_mismatch.nim 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. discard """
  2. action: reject
  3. cmd: '''nim check --hints:off $options $file'''
  4. nimoutFull: true
  5. nimout: '''
  6. tproc_mismatch.nim(38, 52) Error: type mismatch: got <proc (a: int, c: float){.cdecl, noSideEffect, gcsafe.}> but expected 'proc (a: int, c: float){.closure, noSideEffect.}'
  7. Calling convention mismatch: got '{.cdecl.}', but expected '{.closure.}'.
  8. tproc_mismatch.nim(42, 6) Error: type mismatch: got <proc (){.inline, noSideEffect, gcsafe.}>
  9. but expected one of:
  10. proc bar(a: proc ())
  11. first type mismatch at position: 1
  12. required type for a: proc (){.closure.}
  13. but expression 'fn1' is of type: proc (){.inline, noSideEffect, gcsafe.}
  14. Calling convention mismatch: got '{.inline.}', but expected '{.closure.}'.
  15. expression: bar(fn1)
  16. tproc_mismatch.nim(46, 8) Error: type mismatch: got <proc (){.inline, noSideEffect, gcsafe.}> but expected 'proc (){.closure.}'
  17. Calling convention mismatch: got '{.inline.}', but expected '{.closure.}'.
  18. tproc_mismatch.nim(51, 8) Error: type mismatch: got <proc ()> but expected 'proc (){.closure, noSideEffect.}'
  19. Calling convention mismatch: got '{.nimcall.}', but expected '{.closure.}'.
  20. Pragma mismatch: got '{..}', but expected '{.noSideEffect.}'.
  21. tproc_mismatch.nim(55, 8) Error: type mismatch: got <proc (a: int){.noSideEffect, gcsafe.}> but expected 'proc (a: float){.closure.}'
  22. Calling convention mismatch: got '{.nimcall.}', but expected '{.closure.}'.
  23. tproc_mismatch.nim(64, 9) Error: type mismatch: got <proc (a: int)> but expected 'proc (a: int){.closure, gcsafe.}'
  24. Calling convention mismatch: got '{.nimcall.}', but expected '{.closure.}'.
  25. Pragma mismatch: got '{..}', but expected '{.gcsafe.}'.
  26. tproc_mismatch.nim(72, 9) Error: type mismatch: got <proc (a: int): int{.nimcall.}> but expected 'proc (a: int): int{.cdecl.}'
  27. Calling convention mismatch: got '{.nimcall.}', but expected '{.cdecl.}'.
  28. tproc_mismatch.nim(73, 9) Error: type mismatch: got <proc (a: int): int{.cdecl.}> but expected 'proc (a: int): int{.nimcall.}'
  29. Calling convention mismatch: got '{.cdecl.}', but expected '{.nimcall.}'.
  30. '''
  31. """
  32. block: # CallConv mismatch
  33. func a(a: int, c: float) {.cdecl.} = discard
  34. var b: proc(a: int, c: float) {.noSideEffect.} = a
  35. block: # Parameter CallConv mismatch
  36. proc fn1() {.inline.} = discard
  37. proc bar(a: proc()) = discard
  38. bar(fn1)
  39. block: # CallConv mismatch
  40. proc fn1() {.inline.} = discard
  41. var fn: proc()
  42. fn = fn1
  43. block: # Pragma mismatch
  44. var a = ""
  45. proc fn1() = a.add "b"
  46. var fn: proc() {.noSideEffect.}
  47. fn = fn1
  48. block: # Fail match not do to Pragma or CallConv
  49. proc fn1(a: int) = discard
  50. var fn: proc(a: float)
  51. fn = fn1
  52. block: # Infered noSideEffect assign
  53. type Foo = ref object
  54. x0: int
  55. var g0 = Foo(x0: 1)
  56. proc fn1(a: int) = g0.x0 = a
  57. var fn2: proc(a: int)
  58. var fn3: proc(a: int) {.gcsafe.}
  59. fn2 = fn1
  60. fn3 = fn1
  61. block: # Indrection through pragmas
  62. {.pragma: inl1, inline.}
  63. {.pragma: inl2, inline.}
  64. {.pragma: p1, nimcall.}
  65. {.pragma: p2, cdecl.}
  66. var fn1: proc(a: int): int {.inl1, p1.}
  67. var fn2: proc(a: int): int {.inl2, p2.}
  68. fn2 = fn1
  69. fn1 = fn2