@@ -140,46 +140,6 @@ namespace Slang
140
140
return result;
141
141
}
142
142
143
- void insertSubstAtBottom (DeclRefBase & declRef, RefPtr<Substitutions> substToInsert)
144
- {
145
- RefPtr<Substitutions> lastSubst;
146
- auto subst = declRef.substitutions ;
147
- while (subst)
148
- {
149
- if (subst)
150
- lastSubst = subst;
151
- subst = subst->outer ;
152
- }
153
- if (lastSubst)
154
- lastSubst->outer = substToInsert;
155
- else
156
- declRef.substitutions = substToInsert;
157
- }
158
-
159
- RefPtr<ThisTypeSubstitution> getThisTypeSubst (DeclRefBase & declRef, bool insertSubstEntry)
160
- {
161
- RefPtr<ThisTypeSubstitution> thisSubst;
162
- auto subst = declRef.substitutions ;
163
- while (subst)
164
- {
165
- if (auto s = subst.As <ThisTypeSubstitution>())
166
- {
167
- thisSubst = s;
168
- break ;
169
- }
170
- subst = subst->outer ;
171
- }
172
- if (!thisSubst)
173
- {
174
- thisSubst = new ThisTypeSubstitution ();
175
- if (insertSubstEntry)
176
- {
177
- insertSubstAtBottom (declRef, thisSubst);
178
- }
179
- }
180
- return thisSubst;
181
- }
182
-
183
143
RefPtr<DeclRefType> getExprDeclRefType (Expr * expr)
184
144
{
185
145
if (auto typetype = expr->type ->As <TypeType>())
@@ -221,27 +181,35 @@ namespace Slang
221
181
222
182
RefPtr<ThisTypeSubstitution> baseThisTypeSubst;
223
183
if (auto baseDeclRefExpr = baseExpr->As <DeclRefExpr>())
184
+ {
224
185
baseThisTypeSubst = getThisTypeSubst (baseDeclRefExpr->declRef , false );
225
-
186
+ if (auto baseAssocType = baseDeclRefExpr->declRef .As <AssocTypeDecl>())
187
+ {
188
+ baseThisTypeSubst = new ThisTypeSubstitution ();
189
+ baseThisTypeSubst->sourceType = baseDeclRefExpr->type .type ;
190
+ if (auto typetype = baseThisTypeSubst->sourceType .As <TypeType>())
191
+ baseThisTypeSubst->sourceType = typetype->type ;
192
+ }
193
+ }
226
194
if (auto assocTypeDecl = declRef.As <AssocTypeDecl>())
227
195
{
228
- if (!baseThisTypeSubst)
229
- baseThisTypeSubst = new ThisTypeSubstitution ();
230
- expr->type = GetTypeForDeclRef (DeclRef<AssocTypeDecl>(assocTypeDecl.getDecl (), baseThisTypeSubst));
231
-
232
- RefPtr<ThisTypeSubstitution> outerSubst = getThisTypeSubst (*declRefOut, true );
233
- outerSubst->sourceType = expr->type .type ;
234
- if (auto outerTypeType = outerSubst->sourceType .As <TypeType>())
235
- outerSubst->sourceType = outerTypeType->type ;
236
- declRefOut->substitutions = outerSubst;
196
+ auto newThisTypeSubst = new ThisTypeSubstitution ();
197
+ if (baseThisTypeSubst)
198
+ newThisTypeSubst->sourceType = baseThisTypeSubst->sourceType ;
199
+ expr->type = GetTypeForDeclRef (DeclRef<AssocTypeDecl>(assocTypeDecl.getDecl (), newThisTypeSubst));
200
+ auto declOutThisTypeSubst = getNewThisTypeSubst (*declRefOut);
201
+ if (baseThisTypeSubst)
202
+ declOutThisTypeSubst->sourceType = baseThisTypeSubst->sourceType ;
237
203
return expr;
238
204
}
239
205
240
206
// propagate "this-type" substitutions
241
207
if (baseThisTypeSubst)
242
208
{
243
209
if (auto declRefExpr = expr.As <DeclRefExpr>())
244
- insertSubstAtBottom (declRefExpr->declRef , baseThisTypeSubst);
210
+ {
211
+ getNewThisTypeSubst (declRefExpr->declRef )->sourceType = baseThisTypeSubst->sourceType ;
212
+ }
245
213
}
246
214
expr->type = GetTypeForDeclRef (declRef);
247
215
return expr;
@@ -2000,8 +1968,6 @@ namespace Slang
2000
1968
2001
1969
void visitFuncDecl (FuncDecl *functionNode)
2002
1970
{
2003
- if (functionNode->nameAndLoc .name ->text == " test" )
2004
- printf (" break" );
2005
1971
if (functionNode->IsChecked (DeclCheckState::Checked))
2006
1972
return ;
2007
1973
@@ -5861,7 +5827,6 @@ namespace Slang
5861
5827
5862
5828
RefPtr<Expr> CheckInvokeExprWithCheckedOperands (InvokeExpr *expr)
5863
5829
{
5864
-
5865
5830
auto rs = ResolveInvoke (expr);
5866
5831
if (auto invoke = dynamic_cast <InvokeExpr*>(rs.Ptr ()))
5867
5832
{
@@ -5894,9 +5859,6 @@ namespace Slang
5894
5859
5895
5860
RefPtr<Expr> visitInvokeExpr (InvokeExpr *expr)
5896
5861
{
5897
- if (auto mbrExpr = expr->FunctionExpr ->As <MemberExpr>())
5898
- if (mbrExpr->name ->text == " add" )
5899
- printf (" break" );
5900
5862
// check the base expression first
5901
5863
expr->FunctionExpr = CheckExpr (expr->FunctionExpr );
5902
5864
@@ -6631,9 +6593,11 @@ namespace Slang
6631
6593
}
6632
6594
else if (auto constraintDeclRef = declRef.As <GenericTypeConstraintDecl>())
6633
6595
{
6634
- auto type = DeclRefType::Create (session, constraintDeclRef);
6635
- *outTypeResult = type;
6636
- return QualType (getTypeType (type));
6596
+ // When we access a constraint or an inheritance decl (as a member),
6597
+ // we are conceptually performing a "cast" to the given super-type,
6598
+ // with the declaration showing that such a cast is legal.
6599
+ auto type = GetSup (constraintDeclRef);
6600
+ return QualType (type);
6637
6601
}
6638
6602
if ( sink )
6639
6603
{
0 commit comments