transDec (venv, tenv, A.VarDec{name, escape, typ, init, pos}) =
let val {exp=iexp, ty=ity} = transExp(venv,tenv) init
in case ity of E.NIL =>
(case typ of NONE => (error pos "no type defined got NIL assignment"; {venv=venv, tenv=tenv})
| SOME (sym,p) =>
let val styp = actual_ty (lookupTbl (tenv, sym, p))
in case styp of E.RECORD(lst,unique) =>
{venv=Symbol.enter(venv, name, E.VarEntry{ty=E.RECORD(lst,unique), loopvar=false}),tenv=tenv}
| _ => (error p "must be a record type"; {venv=venv, tenv=tenv})
end)
| _ => ((case typ of NONE => ()
| SOME(sym,p) => let val styp = actual_ty (lookupTbl (tenv, sym, p))
in if checkType (styp, ity) then ()
else error p "type mismatch"
end);
{venv=Symbol.enter(venv, name, E.VarEntry{ty=ity, loopvar=false}), tenv=tenv})
end