diff options
-rw-r--r-- | compiler/ast.nim | 4 | ||||
-rw-r--r-- | compiler/semtypes.nim | 4 | ||||
-rw-r--r-- | compiler/semtypinst.nim | 3 | ||||
-rw-r--r-- | tests/notnil/tmust_compile.nim | 26 |
4 files changed, 35 insertions, 2 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index f48ecab34..1576135bb 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -1448,6 +1448,10 @@ proc rawAddSon*(father, son: PType) = add(father.sons, son) if not son.isNil: propagateToOwner(father, son) +proc rawAddSonNoPropagationOfTypeFlags*(father, son: PType) = + if isNil(father.sons): father.sons = @[] + add(father.sons, son) + proc addSonNilAllowed*(father, son: PNode) = if isNil(father.sons): father.sons = @[] add(father.sons, son) diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 9682a33d5..52d992a66 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -296,7 +296,9 @@ proc semArray(c: PContext, n: PNode, prev: PType): PType = base = semTypeNode(c, n.sons[2], nil) # ensure we only construct a tyArray when there was no error (bug #3048): result = newOrPrevType(tyArray, prev, c) - addSonSkipIntLit(result, indx) + # bug #6682: Do not propagate initialization requirements etc for the + # index type: + rawAddSonNoPropagationOfTypeFlags(result, indx) addSonSkipIntLit(result, base) else: localError(n.info, errArrayExpectsTwoTypeParams) diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim index e75ab21bb..1861b9da3 100644 --- a/compiler/semtypinst.nim +++ b/compiler/semtypinst.nim @@ -522,7 +522,8 @@ proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType = if r2.kind in {tyPtr, tyRef}: r = skipTypes(r2, {tyPtr, tyRef}) result.sons[i] = r - propagateToOwner(result, r) + #if result.kind != tyArray or i != 0: + # propagateToOwner(result, r) # bug #4677: Do not instantiate effect lists result.n = replaceTypeVarsN(cl, result.n, ord(result.kind==tyProc)) case result.kind diff --git a/tests/notnil/tmust_compile.nim b/tests/notnil/tmust_compile.nim new file mode 100644 index 000000000..c81c3b16b --- /dev/null +++ b/tests/notnil/tmust_compile.nim @@ -0,0 +1,26 @@ +discard """ + output: '''success''' +""" + +# bug #6682 + +type + Fields = enum + A=1, B, C + + Obj = object + fld: array[Fields, int] + + AsGeneric[T] = array[Fields, T] + Obj2[T] = object + fld: AsGeneric[T] + +var a: Obj # this works + +var arr: array[Fields, int] + +var b = Obj() # this doesn't (also doesn't works with additional fields) + +var z = Obj2[int]() + +echo "success" \ No newline at end of file |