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

Regression: 2.40.2 generates invalid code: variable is already defined in method #3065

Closed
bubenheimer opened this issue Nov 24, 2021 · 2 comments

Comments

@bubenheimer
Copy link

The Kotlin code below generates invalid code in 2.40.2; works fine in 2.39.1 and prior:

    class LifecycleTracker @AssistedInject internal constructor(
        @Assisted lifecycle: Lifecycle,
        private val analytics: FirebaseAnalytics,
        @Assisted private val myName: String
    ) : DefaultLifecycleObserver {
        @AssistedFactory
        sealed interface Factory {
            operator fun Lifecycle.invoke(myName: String): LifecycleTracker
        }

        // ...
    }

This generates the following Java code, which has a duplicate variable name in the invoke method; looks related to using a receiver instead of a parameter for Lifecycle:

    @DaggerGenerated
    @Generated(
        value = "dagger.internal.codegen.ComponentProcessor",
        comments = "https://dagger.dev"
    )
    @SuppressWarnings({
        "unchecked",
        "rawtypes"
    })
    public final class LifecycleTracker_Factory_Impl implements LifecycleTracker.Factory {
        private final LifecycleTracker_Factory delegateFactory;

        LifecycleTracker_Factory_Impl(LifecycleTracker_Factory delegateFactory) {
            this.delegateFactory = delegateFactory;
        }

        @Override
        public LifecycleTracker invoke(Lifecycle myName, String myName) {
            return delegateFactory.get(myName, myName);
        }

        public static Provider<LifecycleTracker.Factory> create(
                LifecycleTracker_Factory delegateFactory) {
            return InstanceFactory.create(new LifecycleTracker_Factory_Impl(delegateFactory));
        }
    }

The build error is variable myName is already defined in method invoke

In 2.39.1 the generated variable name for the receiver in the generated invoke method is $this$invoke.

@bcorso
Copy link

bcorso commented Nov 24, 2021

Thanks, I was able to repro this! Looking into it now.

copybara-service bot pushed a commit that referenced this issue Nov 24, 2021
This CL replaces all usages of XProcessing getName() with a utility class XElements#getSimpleName(XElement) which ensures we use the javac simple name for now.

Fixes #3065

RELNOTES=N/A
PiperOrigin-RevId: 412072237
copybara-service bot pushed a commit that referenced this issue Nov 24, 2021
This CL replaces all usages of XProcessing getName() with a utility class XElements#getSimpleName(XElement) which ensures we use the javac simple name for now.

Fixes #3065

RELNOTES=N/A
PiperOrigin-RevId: 412072237
@bcorso
Copy link

bcorso commented Nov 25, 2021

FYI, this should be fixed now but I likely won't get a release out until Monday.

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 a pull request may close this issue.

2 participants