34
34
import org .ballerinalang .model .tree .OperatorKind ;
35
35
import org .ballerinalang .model .tree .TopLevelNode ;
36
36
import org .ballerinalang .model .tree .expressions .RecordLiteralNode ;
37
+ import org .ballerinalang .model .types .TypeKind ;
37
38
import org .wso2 .ballerinalang .compiler .bir .model .BIRNode ;
38
39
import org .wso2 .ballerinalang .compiler .bir .model .BIRNode .BIRAnnotation ;
39
40
import org .wso2 .ballerinalang .compiler .bir .model .BIRNode .BIRAnnotationAttachment ;
@@ -2434,7 +2435,7 @@ private BIRVariableDcl getOrCreateTypedescVariable(BType type, Location pos) {
2434
2435
return variableDcl ;
2435
2436
}
2436
2437
2437
- variableDcl = findInPackageScope (type );
2438
+ variableDcl = findInDifferentPackage (type );
2438
2439
if (variableDcl != null && variableDcl .initialized ) {
2439
2440
return variableDcl ;
2440
2441
}
@@ -2446,16 +2447,24 @@ private BIRVariableDcl getOrCreateTypedescVariable(BType type, Location pos) {
2446
2447
return this .env .targetOperand .variableDcl ;
2447
2448
}
2448
2449
2449
- private BIRVariableDcl findInPackageScope (BType type ) {
2450
+ private BIRVariableDcl findInDifferentPackage (BType type ) {
2450
2451
BTypeSymbol typeSymbol = type .tsymbol ;
2451
2452
if (typeSymbol == null || typeSymbol .owner .tag != SymTag .PACKAGE ||
2452
2453
isInSameModule (typeSymbol , env .enclPkg .packageID )) {
2453
2454
return null ;
2454
2455
}
2455
2456
BPackageSymbol packageSymbol = (BPackageSymbol ) typeSymbol .owner ;
2456
- Scope .ScopeEntry scopeEntry =
2457
- packageSymbol .scope .lookup (new Name (TYPEDESC + typeSymbol .name .value ));
2458
- BSymbol symbol = scopeEntry .symbol ;
2457
+ BSymbol symbol = packageSymbol .scope .entries .entrySet ().stream ()
2458
+ .filter (entry -> entry .getKey ().value .startsWith (TYPEDESC ))
2459
+ .map (entry -> entry .getValue ().symbol )
2460
+ .filter (entrySymbol -> {
2461
+ BType symbolType = entrySymbol .getType ();
2462
+ return symbolType .getKind () == TypeKind .TYPEDESC &&
2463
+ ((BTypedescType ) symbolType ).constraint == type ;
2464
+ })
2465
+ .findFirst ()
2466
+ .orElse (null );
2467
+
2459
2468
return symbol != null ? getVarRef (createPackageVarRef (symbol )) : null ;
2460
2469
}
2461
2470
@@ -2504,9 +2513,7 @@ private void createNewTypedescInst(BType resolveType, Location position) {
2504
2513
BTypeSymbol typeSymbol = resolveType .tsymbol ;
2505
2514
BIRVariableDcl tempVarDcl = createTempVariable ();
2506
2515
BIROperand toVarRef = new BIROperand (tempVarDcl );
2507
-
2508
2516
BIRNonTerminator .NewTypeDesc newTypeDesc = createNewTypeDesc (position , toVarRef , resolveType , typeSymbol );
2509
-
2510
2517
this .env .targetOperand = toVarRef ;
2511
2518
setScopeAndEmit (newTypeDesc );
2512
2519
}
@@ -2812,7 +2819,6 @@ private void generateListConstructorExpr(BLangListConstructorExpr listConstructo
2812
2819
VarScope .FUNCTION , VarKind .TEMP );
2813
2820
this .env .enclFunc .localVars .add (tempVarDcl );
2814
2821
BIROperand toVarRef = new BIROperand (tempVarDcl );
2815
-
2816
2822
BType listConstructorExprType = listConstructorExpr .getBType ();
2817
2823
2818
2824
List <BLangExpression > exprs = listConstructorExpr .exprs ;
0 commit comments