summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/sem.nim14
-rw-r--r--compiler/vm.nim6
-rw-r--r--lib/system/widestrs.nim3
3 files changed, 17 insertions, 6 deletions
diff --git a/compiler/sem.nim b/compiler/sem.nim
index f639b831a..ed3c0e045 100644
--- a/compiler/sem.nim
+++ b/compiler/sem.nim
@@ -43,7 +43,7 @@ proc activate(c: PContext, n: PNode)
 proc semQuoteAst(c: PContext, n: PNode): PNode
 proc finishMethod(c: PContext, s: PSym)
 
-proc IndexTypesMatch(c: PContext, f, a: PType, arg: PNode): PNode
+proc indexTypesMatch(c: PContext, f, a: PType, arg: PNode): PNode
 
 proc typeMismatch(n: PNode, formal, actual: PType) = 
   if formal.kind != tyError and actual.kind != tyError: 
@@ -63,7 +63,7 @@ proc fitNode(c: PContext, formal: PType, arg: PNode): PNode =
     if result == nil:
       typeMismatch(arg, formal, arg.typ)
       # error correction:
-      result = copyNode(arg)
+      result = copyTree(arg)
       result.typ = formal
 
 var CommonTypeBegin = PType(kind: tyExpr)
@@ -211,7 +211,15 @@ proc semConstExpr(c: PContext, n: PNode): PNode =
       # recompute the types as 'eval' isn't guaranteed to construct types nor
       # that the types are sound:
       result = semExprWithType(c, result)
-      result = fitNode(c, e.typ, result)
+      #result = fitNode(c, e.typ, result) inlined with special case:
+      let arg = result
+      result = indexTypesMatch(c, e.typ, arg.typ, arg)
+      if result == nil:
+        result = arg
+        # for 'tcnstseq' we support [] to become 'seq'
+        if e.typ.skipTypes(abstractInst).kind == tySequence and 
+           arg.typ.skipTypes(abstractInst).kind == tyArrayConstr:
+          arg.typ = e.typ
 
 include hlo, seminst, semcall
 
diff --git a/compiler/vm.nim b/compiler/vm.nim
index 854b491fb..709baf7b2 100644
--- a/compiler/vm.nim
+++ b/compiler/vm.nim
@@ -632,10 +632,10 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): PNode =
         # we pass 'tos.slots' instead of 'regs' so that the compiler can keep
         # 'regs' in a register:
         when hasFFI:
-          if c.globals.sons[prc.position-1].kind == nkEmpty:
+          let prcValue = c.globals.sons[prc.position-1]
+          if prcValue.kind == nkEmpty:
             globalError(c.debug[pc], errGenerated, "canot run " & prc.name.s)
-          let newValue = callForeignFunction(c.globals.sons[prc.position-1],
-                                             prc.typ, tos.slots,
+          let newValue = callForeignFunction(prcValue, prc.typ, tos.slots,
                                              rb+1, rc-1, c.debug[pc])
           if newValue.kind != nkEmpty:
             assert instr.opcode == opcIndCallAsgn
diff --git a/lib/system/widestrs.nim b/lib/system/widestrs.nim
index 6a699274c..d856cc830 100644
--- a/lib/system/widestrs.nim
+++ b/lib/system/widestrs.nim
@@ -9,6 +9,9 @@
 

 ## Nimrod support for C/C++'s `wide strings`:idx:. This is part of the system

 ## module! Do not import it directly!

+
+when not defined(NimString):
+  {.error: "You must not import this module explicitly".}
 

 type

   TUtf16Char* = distinct int16