Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CSharp] : Increase robustness - Block AST #5284

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

khemrajrathore
Copy link
Contributor

No description provided.

* fix methodFullName inside using block

* code refactoring

* Try handling change

* added curly braces
@khemrajrathore
Copy link
Contributor Author

khemrajrathore commented Feb 3, 2025

@ankit-privado can you add more details/description to this PR

@@ -173,4 +173,37 @@ class ControlStructureTests extends CSharpCode2CpgFixture {

}

"having using statement" should {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"having using statement" should {
"a variable defined within a using statement" should {

|}
|""".stripMargin)

"resolve methodFullName" in {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"resolve methodFullName" in {
"partially resolve calls on the defined variable" in {

@@ -362,11 +362,13 @@ trait AstForStatementsCreator(implicit withSchemaValidation: ValidationMode) { t
* Thus, this is lowered as a try-finally, with finally making a call to `Dispose` on the declared variable.
*/
private def astForUsingStatement(usingStmt: DotNetNodeInfo): Seq[Ast] = {
val tryNode = controlStructureNode(usingStmt, ControlStructureTypes.TRY, code(usingStmt))
val tryNode = controlStructureNode(usingStmt, ControlStructureTypes.TRY, code(usingStmt))
val declAst = Try(createDotNetNodeInfo(usingStmt.json(ParserKeys.Declaration))) match {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given we throw away the exception, rather lets do something like

Suggested change
val declAst = Try(createDotNetNodeInfo(usingStmt.json(ParserKeys.Declaration))) match {
val declAst = Try(createDotNetNodeInfo(usingStmt.json(ParserKeys.Declaration))).map(astForNode).getOrElse(Seq.empty[Ast])

@ankit-privado
Copy link
Contributor

@khemrajrathore this PR was to handle code inside the using block. Earlier AST for code under using block wasn't creating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants