summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-11-14 08:33:44 +0100
committerAraq <rumpf_a@web.de>2011-11-14 08:33:44 +0100
commitbec06a0649e1e82f4f9d07ce0126384211c74961 (patch)
tree7f5c4ac86ae0adc4a958d530d3bf8bdc2330c50f
parent395b05f9113d30d1e63390e7a84dbe2a9a55718d (diff)
downloadNim-bec06a0649e1e82f4f9d07ce0126384211c74961.tar.gz
bugfix: s[1..n] = @[] produced wrong C code
-rwxr-xr-xcompiler/ccgexprs.nim14
-rwxr-xr-xcompiler/semexprs.nim17
-rwxr-xr-xcompiler/sigmatch.nim16
-rwxr-xr-xtodo.txt1
4 files changed, 33 insertions, 15 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim
index c0da213c7..a4bf69cfa 100755
--- a/compiler/ccgexprs.nim
+++ b/compiler/ccgexprs.nim
@@ -1213,7 +1213,8 @@ proc genSetLengthSeq(p: BProc, e: PNode, d: var TLoc) =
   InitLocExpr(p, e.sons[1], a)
   InitLocExpr(p, e.sons[2], b)
   var t = skipTypes(e.sons[1].typ, abstractVar)
-  appcg(p, cpsStmts, "$1 = ($3) #setLengthSeq(&($1)->Sup, sizeof($4), $2);$n", [
+  appcg(p, cpsStmts, 
+      "$1 = ($3) #setLengthSeq(&($1)->Sup, sizeof($4), $2);$n", [
       rdLoc(a), rdLoc(b), getTypeDesc(p.module, t),
       getTypeDesc(p.module, t.sons[0])])
 
@@ -1316,7 +1317,7 @@ proc genSetOp(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
     of mIncl:
       var ts = "NI" & $(size * 8)
       binaryStmtInExcl(p, e, d,
-                       "$1 |=(1<<((" & ts & ")($2)%(sizeof(" & ts & ")*8)));$n")
+          "$1 |=(1<<((" & ts & ")($2)%(sizeof(" & ts & ")*8)));$n")
     of mExcl:
       var ts = "NI" & $(size * 8)
       binaryStmtInExcl(p, e, d, "$1 &= ~(1 << ((" & ts & ")($2) % (sizeof(" &
@@ -1375,10 +1376,10 @@ proc genCast(p: BProc, e: PNode, d: var TLoc) =
   if (skipTypes(e.typ, abstractRange).kind in ValueTypes) and
       not (lfIndirect in a.flags):
     putIntoDest(p, d, e.typ, ropef("(*($1*) ($2))",
-                                   [getTypeDesc(p.module, e.typ), addrLoc(a)]))
+        [getTypeDesc(p.module, e.typ), addrLoc(a)]))
   else:
     putIntoDest(p, d, e.typ, ropef("(($1) ($2))",
-                                   [getTypeDesc(p.module, e.typ), rdCharLoc(a)]))
+        [getTypeDesc(p.module, e.typ), rdCharLoc(a)]))
 
 proc genRangeChck(p: BProc, n: PNode, d: var TLoc, magic: string) =
   var a: TLoc
@@ -1386,7 +1387,7 @@ proc genRangeChck(p: BProc, n: PNode, d: var TLoc, magic: string) =
   if optRangeCheck notin p.options:
     InitLocExpr(p, n.sons[0], a)
     putIntoDest(p, d, n.typ, ropef("(($1) ($2))",
-                                   [getTypeDesc(p.module, dest), rdCharLoc(a)]))
+        [getTypeDesc(p.module, dest), rdCharLoc(a)]))
   else:
     InitLocExpr(p, n.sons[0], a)
     putIntoDest(p, d, dest, ropecg(p.module, "(($1)#$5($2, $3, $4))", [
@@ -1403,7 +1404,8 @@ proc genConv(p: BProc, e: PNode, d: var TLoc) =
 proc convStrToCStr(p: BProc, n: PNode, d: var TLoc) =
   var a: TLoc
   initLocExpr(p, n.sons[0], a)
-  putIntoDest(p, d, skipTypes(n.typ, abstractVar), ropef("$1->data", [rdLoc(a)]))
+  putIntoDest(p, d, skipTypes(n.typ, abstractVar), ropef("$1->data",
+      [rdLoc(a)]))
 
 proc convCStrToStr(p: BProc, n: PNode, d: var TLoc) =
   var a: TLoc
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index b9b1d0f99..c1d2f1fec 100755
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -318,16 +318,25 @@ proc fixAbstractType(c: PContext, n: PNode) =
   for i in countup(1, sonsLen(n) - 1): 
     var it = n.sons[i]
     case it.kind
-    of nkHiddenStdConv, nkHiddenSubConv: 
-      if it.sons[1].kind == nkBracket: 
+    of nkHiddenStdConv, nkHiddenSubConv:
+      if it.sons[1].kind == nkBracket:
         it.sons[1] = semArrayConstr(c, it.sons[1])
       if skipTypes(it.typ, abstractVar).kind == tyOpenArray: 
+        #if n.sons[0].kind == nkSym and IdentEq(n.sons[0].sym.name, "[]="):
+        #  debug(n)
+        
         var s = skipTypes(it.sons[1].typ, abstractVar)
-        if (s.kind == tyArrayConstr) and (s.sons[1].kind == tyEmpty): 
+        if s.kind == tyArrayConstr and s.sons[1].kind == tyEmpty: 
           s = copyType(s, getCurrOwner(), false)
           skipTypes(s, abstractVar).sons[1] = elemType(
               skipTypes(it.typ, abstractVar))
           it.sons[1].typ = s
+        elif s.kind == tySequence and s.sons[0].kind == tyEmpty:
+          s = copyType(s, getCurrOwner(), false)
+          skipTypes(s, abstractVar).sons[0] = elemType(
+              skipTypes(it.typ, abstractVar))
+          it.sons[1].typ = s
+          
       elif skipTypes(it.sons[1].typ, abstractVar).kind in
           {tyNil, tyArrayConstr, tyTuple, tySet}: 
         var s = skipTypes(it.typ, abstractVar)
@@ -338,7 +347,7 @@ proc fixAbstractType(c: PContext, n: PNode) =
       n.sons[i] = semArrayConstr(c, it)
     else: 
       if (it.typ == nil): 
-        InternalError(it.info, "fixAbstractType: " & renderTree(it))
+        InternalError(it.info, "fixAbstractType: " & renderTree(it))  
   
 proc skipObjConv(n: PNode): PNode = 
   case n.kind
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim
index 16a93f47f..69982bfa5 100755
--- a/compiler/sigmatch.nim
+++ b/compiler/sigmatch.nim
@@ -504,19 +504,19 @@ proc ParamTypesMatchAux(c: PContext, m: var TCandidate, f, a: PType,
     result = copyTree(arg)
     result.typ = getInstantiatedType(c, arg, m, f) 
     # BUG: f may not be the right key!
-    if (skipTypes(result.typ, abstractVar).kind in {tyTuple}): 
+    if skipTypes(result.typ, abstractVar).kind in {tyTuple}:
       result = implicitConv(nkHiddenStdConv, f, copyTree(arg), m, c) 
       # BUGFIX: use ``result.typ`` and not `f` here
   of isEqual: 
     inc(m.exactMatches)
     result = copyTree(arg)
-    if (skipTypes(f, abstractVar).kind in {tyTuple}): 
+    if skipTypes(f, abstractVar).kind in {tyTuple}: 
       result = implicitConv(nkHiddenStdConv, f, copyTree(arg), m, c)
   of isNone: 
     result = userConvMatch(c, m, f, a, arg) 
     # check for a base type match, which supports openarray[T] without []
     # constructor in a call:
-    if (result == nil) and (f.kind == tyOpenArray): 
+    if result == nil and f.kind == tyOpenArray:
       r = typeRel(m.bindings, base(f), a)
       if r >= isGeneric: 
         inc(m.convMatches)
@@ -525,7 +525,7 @@ proc ParamTypesMatchAux(c: PContext, m: var TCandidate, f, a: PType,
         m.baseTypeMatch = true
       else: 
         result = userConvMatch(c, m, base(f), a, arg)
-  
+
 proc ParamTypesMatch(c: PContext, m: var TCandidate, f, a: PType, 
                      arg: PNode): PNode = 
   if arg == nil or arg.kind != nkSymChoice: 
@@ -711,3 +711,11 @@ proc matches*(c: PContext, n: PNode, m: var TCandidate) =
         setSon(m.call, formal.position + 1, copyTree(formal.ast))
     inc(f)
 
+  when false:
+    if sfSystemModule notin c.module.flags:
+      if includeFilename("temp.nim") == c.module.info.fileIndex:
+        echo "########################"
+        echo m.call.renderTree
+        for i in 1..m.call.len-1:
+          debug m.call[i].typ
+
diff --git a/todo.txt b/todo.txt
index bb5f2c9c0..b47d4958e 100755
--- a/todo.txt
+++ b/todo.txt
@@ -1,7 +1,6 @@
 Version 0.8.14
 ==============
 
-- bug: s[1..n] = @[] produces wrong C code
 - optimize unused constants away (affected by HLO)
 - fix actors.nim: fix thread local storage emulation