parent
3ea3aa633d
commit
1efb5174f2
12 changed files with 290 additions and 171 deletions
|
|
@ -1,5 +1,11 @@
|
|||
# Bug #2022
|
||||
|
||||
discard """
|
||||
output: '''@[97, 45]
|
||||
@[true, false]
|
||||
@[false, false]'''
|
||||
"""
|
||||
|
||||
## The goal of this snippet is to provide and test a construct for general-
|
||||
## purpose, random-access mapping. I use an AST-manipulation-based approach
|
||||
## because it's more efficient than using procedure pointers and less
|
||||
|
|
@ -31,6 +37,7 @@ type Mapped[Input; predicate: static[string]] = object
|
|||
input: Input
|
||||
|
||||
macro map(input, predicate: expr): expr =
|
||||
let predicate = callsite()[2]
|
||||
newNimNode(nnkObjConstr).add(
|
||||
newNimNode(nnkBracketExpr).add(
|
||||
ident"Mapped",
|
||||
|
|
|
|||
|
|
@ -1,14 +1,19 @@
|
|||
discard """
|
||||
output: '''another number: 123
|
||||
yay'''
|
||||
"""
|
||||
|
||||
# Test overloading of procs when used as function pointers
|
||||
|
||||
import strutils
|
||||
|
||||
proc parseInt(x: float): int {.noSideEffect.} = nil
|
||||
proc parseInt(x: bool): int {.noSideEffect.} = nil
|
||||
proc parseInt(x: float32): int {.noSideEffect.} = nil
|
||||
proc parseInt(x: int8): int {.noSideEffect.} = nil
|
||||
proc parseInt(x: TFile): int {.noSideEffect.} = nil
|
||||
proc parseInt(x: char): int {.noSideEffect.} = nil
|
||||
proc parseInt(x: int16): int {.noSideEffect.} = nil
|
||||
proc parseInt(x: float): int {.noSideEffect.} = discard
|
||||
proc parseInt(x: bool): int {.noSideEffect.} = discard
|
||||
proc parseInt(x: float32): int {.noSideEffect.} = discard
|
||||
proc parseInt(x: int8): int {.noSideEffect.} = discard
|
||||
proc parseInt(x: TFile): int {.noSideEffect.} = discard
|
||||
proc parseInt(x: char): int {.noSideEffect.} = discard
|
||||
proc parseInt(x: int16): int {.noSideEffect.} = discard
|
||||
|
||||
proc parseInt[T](x: T): int = echo x; 34
|
||||
|
||||
|
|
@ -19,12 +24,13 @@ var
|
|||
q = TParseInt(parseInt)
|
||||
p: TParseInt = parseInt
|
||||
|
||||
proc takeParseInt(x: proc (y: string): int {.noSideEffect.}): int =
|
||||
proc takeParseInt(x: proc (y: string): int {.noSideEffect.}): int =
|
||||
result = x("123")
|
||||
|
||||
echo "Give a list of numbers (separated by spaces): "
|
||||
var x = stdin.readline.split.map(parseInt).max
|
||||
echo x, " is the maximum!"
|
||||
|
||||
if false:
|
||||
echo "Give a list of numbers (separated by spaces): "
|
||||
var x = stdin.readline.split.map(parseInt).max
|
||||
echo x, " is the maximum!"
|
||||
echo "another number: ", takeParseInt(parseInt)
|
||||
|
||||
|
||||
|
|
|
|||
22
tests/overload/tprefer_specialized_generic.nim
Normal file
22
tests/overload/tprefer_specialized_generic.nim
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
discard """
|
||||
output: '''ref ref T ptr S'''
|
||||
"""
|
||||
|
||||
proc foo[T](x: T) =
|
||||
echo "only T"
|
||||
|
||||
proc foo[T](x: ref T) =
|
||||
echo "ref T"
|
||||
|
||||
proc foo[T, S](x: ref ref T; y: ptr S) =
|
||||
echo "ref ref T ptr S"
|
||||
|
||||
proc foo[T, S](x: ref T; y: ptr S) =
|
||||
echo "ref T ptr S"
|
||||
|
||||
proc foo[T](x: ref T; default = 0) =
|
||||
echo "ref T; default"
|
||||
|
||||
var x: ref ref int
|
||||
var y: ptr ptr int
|
||||
foo(x, y)
|
||||
|
|
@ -1,17 +1,42 @@
|
|||
discard """
|
||||
output: "Version 2 was called."
|
||||
disabled: true
|
||||
output: '''Version 2 was called.
|
||||
This has the highest precedence.
|
||||
This has the second-highest precedence.
|
||||
This has the lowest precedence.'''
|
||||
"""
|
||||
|
||||
# bug #2220
|
||||
when true:
|
||||
type A[T] = object
|
||||
type B = A[int]
|
||||
|
||||
type A[T] = object
|
||||
type B = A[int]
|
||||
proc q[X](x: X) =
|
||||
echo "Version 1 was called."
|
||||
|
||||
proc p[X](x: X) =
|
||||
echo "Version 1 was called."
|
||||
proc q(x: B) =
|
||||
echo "Version 2 was called."
|
||||
|
||||
proc p(x: B) =
|
||||
echo "Version 2 was called."
|
||||
q(B()) # This call reported as ambiguous.
|
||||
|
||||
p(B()) # This call reported as ambiguous.
|
||||
# bug #2219
|
||||
template testPred(a: expr) =
|
||||
block:
|
||||
type A = object of RootObj
|
||||
type B = object of A
|
||||
type SomeA = A|A # A hack to make "A" a typeclass.
|
||||
|
||||
when a >= 3:
|
||||
proc p[X](x: X) =
|
||||
echo "This has the highest precedence."
|
||||
when a >= 2:
|
||||
proc p[X: A](x: X) =
|
||||
echo "This has the second-highest precedence."
|
||||
when a >= 1:
|
||||
proc p[X: SomeA](x: X) =
|
||||
echo "This has the lowest precedence."
|
||||
|
||||
p(B())
|
||||
|
||||
testPred(3)
|
||||
testPred(2)
|
||||
testPred(1)
|
||||
|
|
|
|||
|
|
@ -7,3 +7,12 @@ import algorithm
|
|||
# bug #1657
|
||||
var modules = @["hi", "ho", "ha", "huu"]
|
||||
sort(modules, system.cmp)
|
||||
|
||||
type
|
||||
MyType = object
|
||||
x: string
|
||||
|
||||
proc cmp(a, b: MyType): int = cmp(a.x, b.x)
|
||||
|
||||
var modulesB = @[MyType(x: "ho"), MyType(x: "ha")]
|
||||
sort(modulesB, cmp)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
discard """
|
||||
errormsg: "'"
|
||||
file: "sequtils.nim"
|
||||
line: 416
|
||||
line: 435
|
||||
"""
|
||||
# unfortunately our tester doesn't support multiple lines of compiler
|
||||
# error messages yet...
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue