Skip to content

Conversation

@max-leuthaeuser
Copy link
Contributor

@max-leuthaeuser max-leuthaeuser commented Nov 27, 2025

  • Extension methods are now processed separately, and extension inheritance information is collected and passed through a new global structure. The AST generation for extensions now creates function nodes with a <extension> tag in their fullNames for each function in the extension and binds them appropriately. No TypeDecl is generated for the extension itself.
  • The inheritsFrom logic was updated to work for both regular type declarations and extensions, and inheritance relationships for extensions are now registered globally for later processing in a separate pass.
  • The logic for determining enclosing TypeDecl fullNames was improved in several places, ensuring that references to self and initializer return types are correct.
  • Updated the frontend pass pipeline to include new passes for extension calls and inheritance, and reordered some passes for correctness (TypeDecl and Type generation for used types).

Needs a fix at: https://github.com/ShiftLeftSecurity/codescience/blob/c8d155ffd34ccb6d1f8296a5722a9edeaa8a5c30/securityprofile/src/main/scala/io/shiftleft/securityprofile/passes/finalcustom/swiftsrc/generic/NSURLConnCertCheckPass.scala#L36
Will do that in a PR at CS.

@max-leuthaeuser max-leuthaeuser requested a review from ml86 November 28, 2025 07:03
- fix fullnames with references to extension from libraries
- account for modifiers in compiler json output
Comment on lines +185 to +187
val List(fooCallReceiver) = fooCall.receiver.isIdentifier.l
fooCallReceiver.name shouldBe "self"
fooCallReceiver.typeFullName shouldBe "SwiftTest.Foo"
Copy link
Contributor

Choose a reason for hiding this comment

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

self is should not be given as receiver. It should only be an argument. Receiver relation in the CPG is only valid for dynamically dispatched calls.

Comment on lines +194 to +196
val List(barCallReceiverCall) = barCall.receiver.isIdentifier.l
barCallReceiverCall.name shouldBe "self"
barCallReceiverCall.typeFullName shouldBe "SwiftTest.Foo"
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above.

fooTypeDecl.fullName shouldBe "ModuleA.Foo"

val List(foo) = cpg.method.nameExact("foo").l
foo.fullName shouldBe "ModuleA.Foo<extension>.foo:()->()"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does foo not have the full name ModuleA.ModuleA.Foo<extension>.foo:()->()?
Seems like you use a different naming pattern for extension in the same module as the extended type. I think a uniform naming schema is better or am I missing some reason other than the shorter full name?

* "Test0.swift:<global>.Foo<extension>.someOtherFunc:()->ANY" )
*/

typeDeclFoo.inheritsFromTypeFullName.sorted.l shouldBe List("AnotherProtocol", "Bar", "SomeProtocol")
Copy link
Contributor

Choose a reason for hiding this comment

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

These are not full names. We need to talk about your type full name concept. As those contain file names they do not seem appropriate for linking.

* @param extensionFullNameMapping
* mapping from compiler generated methodFullName -> CPG extension methodFullName (for uniqueness)
*/
class ExtensionCallPass(cpg: Cpg, extensionFullNameMapping: Map[String, String])
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the approach of fixing up the call sites later has reached its end because as mentioned about the receiver edges are wrong for static calls. Of course we could now remove them here but a pre-pass which collects the necessary information to directly generate the correct calls seems more appropriate.

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