This is strange, I'm generating a function in an a...
# compiler
a
This is strange, I'm generating a function in an abstract (code in 🧵) but it's being generated as a static function. It also gets
$main
added to the function name.
Copy code
addFunction {
    this.name = Name.identifier(nameAllocator.newName(name))
    visibility = if (isPublic) DescriptorVisibilities.PUBLIC else DescriptorVisibilities.INTERNAL
    modality = Modality.ABSTRACT
    this.returnType = returnType.type.toIrType(environment)
}.apply {
    if (sourceType != null) {
        addValueParameter(sourceType, nameAllocator)
    }
    annotations = buildList {
        add(environment.renderEngine.createAnnotation(bindingAnnotation))
        addAll(mode.asAnnotations())
        addAll(returnType.qualifiers)
    }
}
This is how the class comes out:
Copy code
public abstract class se.ansman.dagger.auto.AutoBindFooImplSingletonModule {
  private se.ansman.dagger.auto.AutoBindFooImplSingletonModule();
  public static abstract se.ansman.dagger.auto.Foo bindFooImplAsFoo$main(se.ansman.dagger.auto.FooImpl);
}
Ah, looks like I need this:
Copy code
dispatchReceiverParameter = thisReceiver
The
$main
issue still remains
u
Names of internal functions declared in classes are mangled by default. You can workaround it by adding a
@PublishedApi
annotation (
StandardClassIds.Annotations.PublishedApi
)
a
Oh yeah, I forgot mangling. Thanks!