diff --git a/src/nimony/sem.nim b/src/nimony/sem.nim index 4dd2f879..a63fb6f0 100644 --- a/src/nimony/sem.nim +++ b/src/nimony/sem.nim @@ -1772,12 +1772,27 @@ proc semObjectType(c: var SemContext; n: var Cursor) = semLocal(c, n, FldY) wantParRi c, n -proc semTupleType(c: var SemContext; n: var Cursor) = - takeToken c, n +proc semTupleFieldType(c: var SemContext; elemType: var Cursor; context: TypeDeclContext; i: int) = + c.dest.add parLeToken(pool.tags.getOrIncl($FldS), elemType.info) # start field + c.dest.add identToken(pool.strings.getOrIncl("Field" & $i), elemType.info) + c.dest.addDotToken() # export marker + c.dest.addDotToken() # pragmas + semLocalTypeImpl c, elemType, context + c.dest.addDotToken() # value + c.dest.addParRi() # end field + +proc semTupleType(c: var SemContext; n: var Cursor; context: TypeDeclContext) = + c.dest.add parLeToken(TupleT, n.info) + inc n # tuple fields: withNewScope c: - while n.substructureKind == FldS: - semLocal(c, n, FldY) + var i = 0 + while n.kind != ParRi: + if n.substructureKind == FldS: + semLocal(c, n, FldY) + else: + semTupleFieldType(c, n, context, i) + inc i wantParRi c, n type @@ -2216,6 +2231,8 @@ proc semLocalTypeImpl(c: var SemContext; n: var Cursor; context: TypeDeclContext inc n semLocalTypeImpl c, n, context skipParRi n + elif exprKind(n) == TupleConstrX: + semTupleType(c, n, context) elif isOrExpr(n): c.dest.addParLe(OrT, info) inc n # tag @@ -2280,7 +2297,7 @@ proc semLocalTypeImpl(c: var SemContext; n: var Cursor; context: TypeDeclContext of TupleT: if tryTypeClass(c, n): return - semTupleType c, n + semTupleType c, n, context of ArrayT: if tryTypeClass(c, n): return @@ -3528,7 +3545,7 @@ proc semTupleConstr(c: var SemContext, it: var Item) = typ.addParRi() let typeStart = c.dest.len var t = typ.cursorAt(0) - semTupleType(c, t) + semTupleType(c, t, InLocalDecl) it.typ = typeToCursor(c, typeStart) c.dest.shrink typeStart commonType c, it, exprStart, origExpected diff --git a/tests/nimony/sysbasics/ttuples.nim b/tests/nimony/sysbasics/ttuples.nim new file mode 100644 index 00000000..07ed3a72 --- /dev/null +++ b/tests/nimony/sysbasics/ttuples.nim @@ -0,0 +1,7 @@ +type + Tuple0 = tuple[a: int, b: int, c: int] + Tuple = (int, int, int) + +var x0: Tuple = (1, 2, 3) +var x1: Tuple0 +var x2 = (1, 2, 3, 34, 5.6)