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

Adding providers to DataGenerator via lambda is ambiguous #828

Open
rlnt opened this issue Apr 20, 2024 · 5 comments
Open

Adding providers to DataGenerator via lambda is ambiguous #828

rlnt opened this issue Apr 20, 2024 · 5 comments
Labels
triage Needs triaging and confirmation

Comments

@rlnt
Copy link

rlnt commented Apr 20, 2024

Minecraft Version: 1.20.4
NeoForge Version: 20.4.232
Logs: https://gist.github.com/rlnt/2866adea220d3f8e80aa6771a8357569

Steps to Reproduce:

  1. Create a class that extends the NeoForge LanguageProvider
  2. Create a method where you have the GatherDataEvent as parameter
  3. Get the generator from the event via event.getGenerator()
  4. Call the addProvider method on the generator that uses the DataProvider.Factory<T>

Description of issue:
You can't compile the code because the call is ambiguous.

Edit: code snippets because the log is a bit odd

public final class LazierLang extends LanguageProvider {

    LazierLang(PackOutput output) {
        super(output, BuildConfig.MOD_ID, "en_us");
    }

    @Override
    protected void addTranslations() {
    }
}
public final class DataGeneration {

    private DataGeneration() {}

    public static void init(GatherDataEvent event) {
        DataGenerator generator = event.getGenerator();
        generator.addProvider(event.includeClient(), LazierLang::new);
    }
}
@rlnt rlnt added the triage Needs triaging and confirmation label Apr 20, 2024
@KnightMiner
Copy link

Don't you need a new operator to create an instance of your data provider?

@shartte
Copy link
Contributor

shartte commented Apr 20, 2024

He means:

generator.addProvider(true, Provider::new)

javac complains that this is ambiguous

@Shadows-of-Fire
Copy link
Contributor

Is this just poor method resolution on javac's side? The two method signatures are

public <T extends DataProvider> T addProvider(boolean run, DataProvider.Factory<T> factory);
public <T extends DataProvider> T addProvider(boolean run, T provider);

There's no question that T::new should not bind to T

@KnightMiner
Copy link

I think the problem is both take the same parameter (constructor and the datagen run method), just differ in return types.

@rlnt
Copy link
Author

rlnt commented May 3, 2024

I assumed that it may be ambiguous due to T referring to the DataProvider interface which only has one method and is then interpreted as a functional interface as well. The @FunctionalInterface annotation in Java is optional and just an indicator.

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

No branches or pull requests

4 participants