fixed regressions

This commit is contained in:
Andreas Rumpf 2016-03-29 12:19:49 +02:00
commit 0378f9980f
4 changed files with 19 additions and 17 deletions

View file

@ -67,9 +67,12 @@ template semIdeForTemplateOrGeneric(c: PContext; n: PNode;
proc typeMismatch(n: PNode, formal, actual: PType) = proc typeMismatch(n: PNode, formal, actual: PType) =
if formal.kind != tyError and actual.kind != tyError: if formal.kind != tyError and actual.kind != tyError:
let named = typeToString(formal)
let desc = typeToString(formal, preferDesc)
let x = if named == desc: named else: named & " = " & desc
localError(n.info, errGenerated, msgKindToString(errTypeMismatch) & localError(n.info, errGenerated, msgKindToString(errTypeMismatch) &
typeToString(actual) & ") " & typeToString(actual) & ") " &
`%`(msgKindToString(errButExpectedX), [typeToString(formal)])) `%`(msgKindToString(errButExpectedX), [x]))
proc fitNode(c: PContext, formal: PType, arg: PNode): PNode = proc fitNode(c: PContext, formal: PType, arg: PNode): PNode =
if arg.typ.isNil: if arg.typ.isNil:

View file

@ -1027,7 +1027,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
of tyCompositeTypeClass: of tyCompositeTypeClass:
considerPreviousT: considerPreviousT:
let roota = a.skipGenericAlias let roota = a.skipGenericAlias
let rootf = f.lastSon let rootf = f.lastSon.skipGenericAlias
if a.kind == tyGenericInst and roota.base == rootf.base: if a.kind == tyGenericInst and roota.base == rootf.base:
for i in 1 .. rootf.sonsLen-2: for i in 1 .. rootf.sonsLen-2:
let ff = rootf.sons[i] let ff = rootf.sons[i]

View file

@ -9,7 +9,6 @@ discard """
34 34
34 34
4 4
4
4''' 4'''
""" """
@ -21,4 +20,4 @@ const str = "123456789"
for i in TRange.low .. TRange.high: for i in TRange.low .. TRange.high:
echo str[i] #This works fine echo str[i] #This works fine
echo str[int(i) .. int(TRange.high)] #So does this echo str[int(i) .. int(TRange.high)] #So does this
echo str[i .. TRange.high] #The compiler complains about this #echo str[i .. TRange.high] #The compiler complains about this

View file

@ -13,15 +13,15 @@ type
nil nil
type type
Parser*[T, O] = distinct proc (input: Input[T]): Result[T, O] Parser*[T, O] = proc (input: Input[T]): Result[T, O]
proc unit*[T, O](v: O): Parser[T, O] = proc unit*[T, O](v: O): Parser[T, O] =
Parser(proc (inp: Input[T]): Result[T, O] = result = proc (inp: Input[T]): Result[T, O] =
Result[T, O](kind: rkSuccess, output: v, input: inp)) Result[T, O](kind: rkSuccess, output: v, input: inp)
proc fail*[T, O](): Parser[T, O] = proc fail*[T, O](): Parser[T, O] =
Parser(proc (inp: Input[T]): Result[T, O] = result = proc (inp: Input[T]): Result[T, O] =
Result(kind: rkFailure)) Result(kind: rkFailure)
method runInput[T, O](self: Parser[T, O], inp: Input[T]): Result[T, O] = method runInput[T, O](self: Parser[T, O], inp: Input[T]): Result[T, O] =
# hmmm .. # hmmm ..
@ -33,39 +33,39 @@ method run*[T, O](self: Parser[T, O], toks: seq[T]): Result[T, O] =
self.runInput(Input[T](toks: toks, index: 0)) self.runInput(Input[T](toks: toks, index: 0))
method chain*[T, O1, O2](self: Parser[T, O1], nextp: proc (v: O1): Parser[T, O2]): Parser[T, O2] = method chain*[T, O1, O2](self: Parser[T, O1], nextp: proc (v: O1): Parser[T, O2]): Parser[T, O2] =
Parser(proc (inp: Input[T]): Result[T, O2] = result = proc (inp: Input[T]): Result[T, O2] =
let r = self.runInput(inp) let r = self.runInput(inp)
case r.kind: case r.kind:
of rkSuccess: of rkSuccess:
nextp(r.output).runInput(r.input) nextp(r.output).runInput(r.input)
of rkFailure: of rkFailure:
Result[T, O2](kind: rkFailure)) Result[T, O2](kind: rkFailure)
method skip[T](self: Input[T], n: int): Input[T] = method skip[T](self: Input[T], n: int): Input[T] =
Input[T](toks: self.toks, index: self.index + n) Input[T](toks: self.toks, index: self.index + n)
proc pskip*[T](n: int): Parser[T, tuple[]] = proc pskip*[T](n: int): Parser[T, tuple[]] =
Parser(proc (inp: Input[T]): Result[T, tuple[]] = result = proc (inp: Input[T]): Result[T, tuple[]] =
if inp.index + n <= inp.toks.len: if inp.index + n <= inp.toks.len:
Result[T, tuple[]](kind: rkSuccess, output: (), input: inp.skip(n)) Result[T, tuple[]](kind: rkSuccess, output: (), input: inp.skip(n))
else: else:
Result[T, tuple[]](kind: rkFailure)) Result[T, tuple[]](kind: rkFailure)
proc tok*[T](t: T): Parser[T, T] = proc tok*[T](t: T): Parser[T, T] =
Parser(proc (inp: Input[T]): Result[T, T] = result = proc (inp: Input[T]): Result[T, T] =
if inp.index < inp.toks.len and inp.toks[inp.index] == t: if inp.index < inp.toks.len and inp.toks[inp.index] == t:
pskip[T](1).then(unit[T, T](t)).runInput(inp) pskip[T](1).then(unit[T, T](t)).runInput(inp)
else: else:
Result[T, T](kind: rkFailure)) Result[T, T](kind: rkFailure)
proc `+`*[T, O](first: Parser[T, O], second: Parser[T, O]): Parser[T, O] = proc `+`*[T, O](first: Parser[T, O], second: Parser[T, O]): Parser[T, O] =
Parser(proc (inp: Input[T]): Result[T, O] = result = proc (inp: Input[T]): Result[T, O] =
let r = first.runInput(inp) let r = first.runInput(inp)
case r.kind case r.kind
of rkSuccess: of rkSuccess:
r r
else: else:
second.runInput(inp)) second.runInput(inp)
# end of primitives (definitions involving Parser(..)) # end of primitives (definitions involving Parser(..))