@@ -35,13 +35,7 @@ typealias VarTable Array{Any,1}
3535type VarState
3636 typ
3737 undef:: Bool
38- function VarState (typ:: ANY , undef:: Bool )
39- if isa (typ, DataType) && isdefined (typ, :instance )
40- # replace singleton types with their equivalent Const object
41- typ = Const (typ. instance)
42- end
43- return new (typ, undef)
44- end
38+ VarState (typ:: ANY , undef:: Bool ) = new (typ, undef)
4539end
4640
4741immutable Const
@@ -115,11 +109,11 @@ type InferenceState
115109 if linfo. def. isva
116110 if atypes === Tuple
117111 if la > 1
118- atypes = Tuple{Any[Any for i= 1 : la - 1 ]. .. , Tuple. parameters[1 ]}
112+ atypes = Tuple{Any[Any for i = 1 : (la - 1 ) ]. .. , Tuple. parameters[1 ]}
119113 end
120- s[1 ][la] = VarState (Tuple,false )
114+ s[1 ][la] = VarState (Tuple, false )
121115 else
122- s[1 ][la] = VarState (tuple_tfunc (limit_tuple_depth (tupletype_tail (atypes,la))),false )
116+ s[1 ][la] = VarState (tuple_tfunc (limit_tuple_depth (tupletype_tail (atypes, la))), false )
123117 end
124118 la -= 1
125119 end
@@ -135,17 +129,25 @@ type InferenceState
135129 if isa (lastatype, TypeVar)
136130 lastatype = lastatype. ub
137131 end
132+ if isa (lastatype, DataType) && isdefined (lastatype, :instance )
133+ # replace singleton types with their equivalent Const object
134+ lastatype = Const (lastatype. instance)
135+ end
138136 if laty > la
139137 laty = la
140138 end
141- for i= 1 : laty
139+ for i = 1 : laty
142140 atyp = atypes. parameters[i]
143141 if isa (atyp, TypeVar)
144142 atyp = atyp. ub
145143 end
144+ if isa (atyp, DataType) && isdefined (atyp, :instance )
145+ # replace singleton types with their equivalent Const object
146+ atyp = Const (atyp. instance)
147+ end
146148 s[1 ][i] = VarState (atyp, false )
147149 end
148- for i= laty+ 1 : la
150+ for i = ( laty + 1 ) : la
149151 s[1 ][i] = VarState (lastatype, false )
150152 end
151153 else
@@ -676,12 +678,15 @@ function invoke_tfunc(f::ANY, types::ANY, argtype::ANY, sv::InferenceState)
676678end
677679
678680function tuple_tfunc (argtype:: ANY )
679- if isa (argtype,DataType) && argtype. name === Tuple. name
680- p = map (x-> (isType (x) && ! isa (x. parameters[1 ],TypeVar) ? typeof (x. parameters[1 ]) : x),
681+ if isa (argtype, DataType) && argtype. name === Tuple. name
682+ p = map (x-> (isType (x) && ! isa (x. parameters[1 ], TypeVar) ? typeof (x. parameters[1 ]) : x),
681683 argtype. parameters)
682- return Tuple{p... }
684+ t = Tuple{p... }
685+ # replace a singleton type with its equivalent Const object
686+ isdefined (t, :instance ) && return Const (t. instance)
687+ return t
683688 end
684- argtype
689+ return argtype
685690end
686691
687692function builtin_tfunction (f:: ANY , argtypes:: Array{Any,1} , sv:: InferenceState )
@@ -1228,6 +1233,10 @@ function abstract_eval(e::ANY, vtypes::VarTable, sv::InferenceState)
12281233 # no need to use a typevar as the type of an expression
12291234 t = t. ub
12301235 end
1236+ if isa (t, DataType) && isdefined (t, :instance )
1237+ # replace singleton types with their equivalent Const object
1238+ t = Const (t. instance)
1239+ end
12311240 e. typ = t
12321241 return t
12331242end
0 commit comments