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

Feature request: backport KSP's improved method signatures in error messages to apt #3994

Closed
ZacSweers opened this issue Aug 3, 2023 · 1 comment

Comments

@ZacSweers
Copy link

ZacSweers commented Aug 3, 2023

(originally from here: #3991 (comment))

The error reported for multiple @Inject constructors in KSP is better, but also has a subtle message difference.

package com.squareup.test

import javax.inject.Inject

class InjectClass @Inject constructor() {
  @Inject constructor(string: String)
}

Kapt error

Type com.squareup.test.InjectClass may only contain one injected constructor. Found: [@Inject com.squareup.test.InjectClass, @Inject com.squareup.test.InjectClass]

KSP error

Type com.squareup.test.InjectClass may only contain one injected constructor. Found: [@Inject com.squareup.test.InjectClass(), @Inject com.squareup.test.InjectClass(String)]

Namely - the KSP error is better in this case as it disambiguates the constructors by their parameters with a fuller description.

A similar change can be seen with error reporting around multiple assisted factories.

package com.squareup.test

import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject

data class AssistedService @AssistedInject constructor(
  val int: Int,
  @Assisted val string: String
)

interface AssistedServiceFactory1 {
  fun createParent(string: String): AssistedService
}

@AssistedFactory
interface AssistedServiceFactory : AssistedServiceFactory1 {
  fun create(string: String): AssistedService
}

Kapt

The @AssistedFactory-annotated type should contain a single abstract, non-default method but found multiple: [com.squareup.test.AssistedServiceFactory.create, com.squareup.test.AssistedServiceFactory1.createParent]

KSP

The @AssistedFactory-annotated type should contain a single abstract, non-default method but found multiple: [com.squareup.test.AssistedServiceFactory1.createParent(String), com.squareup.test.AssistedServiceFactory.create(String)]
@ZacSweers
Copy link
Author

D'oh, nevermind this is something our tests are doing to sanitize the error messages. Apologies for the noise!

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

No branches or pull requests

1 participant