@@ -147,26 +147,64 @@ namespace Slang
147
147
{
148
148
if (baseExpr)
149
149
{
150
+ RefPtr<Expr> expr;
151
+
150
152
if (baseExpr->type ->As <TypeType>())
151
153
{
152
- auto expr = new StaticMemberExpr ();
153
- expr ->loc = loc;
154
- expr ->BaseExpression = baseExpr;
155
- expr ->name = declRef.GetName ();
156
- expr ->type = GetTypeForDeclRef (declRef);
157
- expr ->declRef = declRef;
158
- return expr;
154
+ auto sexpr = new StaticMemberExpr ();
155
+ sexpr ->loc = loc;
156
+ sexpr ->BaseExpression = baseExpr;
157
+ sexpr ->name = declRef.GetName ();
158
+ sexpr ->type = GetTypeForDeclRef (declRef);
159
+ sexpr ->declRef = declRef;
160
+ expr = sexpr ;
159
161
}
160
162
else
161
163
{
162
- auto expr = new MemberExpr ();
163
- expr->loc = loc;
164
- expr->BaseExpression = baseExpr;
165
- expr->name = declRef.GetName ();
166
- expr->type = GetTypeForDeclRef (declRef);
167
- expr->declRef = declRef;
168
- return expr;
164
+ auto sexpr = new MemberExpr ();
165
+ sexpr->loc = loc;
166
+ sexpr->BaseExpression = baseExpr;
167
+ sexpr->name = declRef.GetName ();
168
+ sexpr->type = GetTypeForDeclRef (declRef);
169
+ sexpr->declRef = declRef;
170
+ expr = sexpr;
171
+ }
172
+ if (auto assocTypeDeclRef = declRef.As <AssocTypeDecl>())
173
+ {
174
+ if (auto genConstraintType = baseExpr->type ->As <GenericConstraintDeclRefType>())
175
+ {
176
+ // if this is a reference from a generic parameter, we need to generate a AssocTypeDeclRefType type.
177
+ // for example, if we have an expression T.U where T:ISimple, and U is an associated type defined in ISimple.
178
+ // then this expression should evaluate to AssocTypeDeclRefType(T, U).
179
+ auto assocTypeDeclType = new AssocTypeDeclRefType ();
180
+ assocTypeDeclType->declRef = assocTypeDeclRef;
181
+ assocTypeDeclType->sourceType = genConstraintType->subType ;
182
+ assocTypeDeclType->setSession (getSession ());
183
+ expr->type = QualType (getTypeType (assocTypeDeclType));
184
+ }
169
185
}
186
+ else if (auto funcDeclRef = declRef.As <CallableDecl>())
187
+ {
188
+ if (auto genConstraintType = baseExpr->type ->As <GenericConstraintDeclRefType>())
189
+ {
190
+ // if this is call expression, propagate the source associated type to the result type
191
+ auto funcType = expr->type ->As <FuncType>();
192
+ if (auto assocRsType = funcType->resultType .As <AssocTypeDeclRefType>())
193
+ {
194
+ RefPtr<FuncType> newFuncType = new FuncType ();
195
+ newFuncType->paramTypes = funcType->paramTypes ;
196
+ RefPtr<AssocTypeDeclRefType> newRsType = new AssocTypeDeclRefType ();
197
+ newRsType->declRef = assocRsType->declRef ;
198
+ newRsType->sourceType = genConstraintType->subType ;
199
+ newRsType->setSession (getSession ());
200
+ newFuncType->resultType = newRsType;
201
+ newFuncType->setSession (funcType->getSession ());
202
+ expr->type = QualType (newFuncType);
203
+ }
204
+
205
+ }
206
+ }
207
+ return expr;
170
208
}
171
209
else
172
210
{
@@ -1878,7 +1916,6 @@ namespace Slang
1878
1916
VisitFunctionDeclaration (functionNode);
1879
1917
// TODO: This should really onlye set "checked header"
1880
1918
functionNode->SetCheckState (DeclCheckState::Checked);
1881
-
1882
1919
// TODO: should put the checking of the body onto a "work list"
1883
1920
// to avoid recursion here.
1884
1921
if (functionNode->Body )
@@ -2309,7 +2346,6 @@ namespace Slang
2309
2346
{
2310
2347
if (functionNode->IsChecked (DeclCheckState::CheckedHeader)) return ;
2311
2348
functionNode->SetCheckState (DeclCheckState::CheckingHeader);
2312
-
2313
2349
this ->function = functionNode;
2314
2350
auto returnType = CheckProperType (functionNode->ReturnType );
2315
2351
functionNode->ReturnType = returnType;
@@ -4366,7 +4402,7 @@ namespace Slang
4366
4402
4367
4403
4368
4404
callExpr->FunctionExpr = baseExpr;
4369
- callExpr->type = QualType (candidate.resultType );
4405
+ callExpr->type = QualType (candidate.resultType );// QualType(baseExpr->type->As<FuncType>()->resultType);
4370
4406
4371
4407
// A call may yield an l-value, and we should take a look at the candidate to be sure
4372
4408
if (auto subscriptDeclRef = candidate.item .declRef .As <SubscriptDecl>())
@@ -4557,7 +4593,9 @@ namespace Slang
4557
4593
OverloadCandidate candidate;
4558
4594
candidate.flavor = OverloadCandidate::Flavor::Func;
4559
4595
candidate.item = item;
4560
- candidate.resultType = GetResultType (funcDeclRef);
4596
+ auto baseExpr = ConstructLookupResultExpr (
4597
+ item, context.baseExpr , context.funcLoc );
4598
+ candidate.resultType = baseExpr->type ->As <FuncType>()->resultType ; // GetResultType(funcDeclRef);
4561
4599
4562
4600
AddOverloadCandidate (context, candidate);
4563
4601
}
@@ -5717,10 +5755,6 @@ namespace Slang
5717
5755
5718
5756
RefPtr<Expr> visitInvokeExpr (InvokeExpr *expr)
5719
5757
{
5720
- if (auto appExpr = expr->FunctionExpr ->As <GenericAppExpr>())
5721
- if (auto varExpr = appExpr->FunctionExpr ->As <VarExpr>())
5722
- if (varExpr->name ->text == " test" )
5723
- printf (" break" );
5724
5758
// check the base expression first
5725
5759
expr->FunctionExpr = CheckExpr (expr->FunctionExpr );
5726
5760
@@ -6453,7 +6487,7 @@ namespace Slang
6453
6487
// When we access a constraint or an inheritance decl (as a member),
6454
6488
// we are conceptually performing a "cast" to the given super-type,
6455
6489
// with the declaration showing that such a cast is legal.
6456
- auto type = GetSup (constraintDeclRef);
6490
+ auto type = new GenericConstraintDeclRefType (session, GetSub (constraintDeclRef), GetSup (constraintDeclRef) );
6457
6491
return QualType (type);
6458
6492
}
6459
6493
else if (auto funcDeclRef = declRef.As <CallableDecl>())
@@ -6463,7 +6497,8 @@ namespace Slang
6463
6497
}
6464
6498
else if (auto assocTypeDeclRef = declRef.As <AssocTypeDecl>())
6465
6499
{
6466
- auto type = DeclRefType::Create (session, assocTypeDeclRef);
6500
+ auto type = new AssocTypeDeclRefType (assocTypeDeclRef);
6501
+ type->setSession (session);
6467
6502
*outTypeResult = type;
6468
6503
return QualType (getTypeType (type));
6469
6504
}
0 commit comments