From a97ead479213ce350de03df0a4f2403039919122 Mon Sep 17 00:00:00 2001 From: rdulmina Date: Tue, 19 Nov 2024 16:37:22 +0530 Subject: [PATCH] Address review suggestions --- .../ballerinalang/compiler/bir/BIRGen.java | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGen.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGen.java index 96b78540bdff..435456aec706 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGen.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGen.java @@ -2409,10 +2409,6 @@ private BIRNonTerminator.NewStructure createNewStructureInst(BIROperand typeDesc return new BIRNonTerminator.NewStructure(pos, toVarRef, typeDesc, fields); } - public String getTypedescFieldName(String name) { - return "$typedesc$" + name; - } - private BIRVariableDcl getTypedescVariable(BType type, Location pos) { Supplier[] checks = new Supplier[] { () -> findInPackageScope(type), @@ -2437,17 +2433,15 @@ private BIRVariableDcl getTypedescVariable(BType type, Location pos) { private BIRVariableDcl findInPackageScope(BType type) { BTypeSymbol typeSymbol = type.tsymbol; - if (typeSymbol != null && typeSymbol.owner.tag == SymTag.PACKAGE && - !isInSameModule(typeSymbol, env.enclPkg.packageID)) { - BPackageSymbol packageSymbol = (BPackageSymbol) typeSymbol.owner; - Scope.ScopeEntry scopeEntry = - packageSymbol.scope.lookup(new Name(getTypedescFieldName(typeSymbol.name.value))); - BSymbol symbol = scopeEntry.symbol; - if (symbol != null) { - return getVarRef(createPackageVarRef(symbol)); - } + if (typeSymbol == null || typeSymbol.owner.tag != SymTag.PACKAGE || + isInSameModule(typeSymbol, env.enclPkg.packageID)) { + return null; } - return null; + BPackageSymbol packageSymbol = (BPackageSymbol) typeSymbol.owner; + Scope.ScopeEntry scopeEntry = + packageSymbol.scope.lookup(new Name(TYPEDESC + typeSymbol.name.value)); + BSymbol symbol = scopeEntry.symbol; + return symbol != null? getVarRef(createPackageVarRef(symbol)) : null; } private BLangPackageVarRef createPackageVarRef(BSymbol symbol) {