summary refs log blame commit diff stats
path: root/tests/concepts/t3330.nim
blob: 8021db8278ad99c3a8d6e86609266678999dd6d0 (plain) (tree)
1
2
3
4
5
6
7
8
9
           
                                                
           
                                                            
                    
                        
                                                                    
                                           
                                    
                           
                                      
                                      


                                      
                                  


                                      
                                   


                                      
                                


                                      
                                      
                                    
                           
                                      



                                      
 





                                                         

   
 


















                                             
discard """
errormsg: "type mismatch: got <Bar[system.int]>"
nimout: '''
t3330.nim(63, 4) Error: type mismatch: got <Bar[system.int]>
but expected one of:
proc test(foo: Foo[int])
t3330.nim(48, 8) Hint: Non-matching candidates for add(k, string, T)
proc add[T](x: var seq[T]; y: openArray[T])
  first type mismatch at position: 1
  required type: var seq[T]
  but expression 'k' is of type: Alias
proc add(result: var string; x: float)
  first type mismatch at position: 1
  required type: var string
  but expression 'k' is of type: Alias
proc add(x: var string; y: string)
  first type mismatch at position: 1
  required type: var string
  but expression 'k' is of type: Alias
proc add(x: var string; y: cstring)
  first type mismatch at position: 1
  required type: var string
  but expression 'k' is of type: Alias
proc add[T](x: var seq[T]; y: T)
  first type mismatch at position: 1
  required type: var seq[T]
  but expression 'k' is of type: Alias
proc add(result: var string; x: int64)
  first type mismatch at position: 1
  required type: var string
  but expression 'k' is of type: Alias
proc add(x: var string; y: char)
  first type mismatch at position: 1
  required type: var string
  but expression 'k' is of type: Alias

t3330.nim(48, 8) template/generic instantiation from here
t3330.nim(55, 6) Foo: 'bar.value' cannot be assigned to
t3330.nim(48, 8) template/generic instantiation from here
t3330.nim(56, 6) Foo: 'bar.x' cannot be assigned to

expression: test(bar)'''
"""


type
  Foo[T] = concept k
    add(k, string, T)

  Bar[T] = object
    value: T
    x: string

proc add[T](bar: Bar[T], x: string, val: T) =
  bar.value = val
  bar.x = x

proc test(foo: Foo[int]) =
  foo.add("test", 42)
  echo(foo.x)

var bar = Bar[int]()
bar.test()