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

The type parameters aren't correctly inferred on function pointers #50096

Closed
KyouyamaKazusa0805 opened this issue Dec 22, 2020 · 8 comments · Fixed by #50249
Closed

The type parameters aren't correctly inferred on function pointers #50096

KyouyamaKazusa0805 opened this issue Dec 22, 2020 · 8 comments · Fixed by #50249
Assignees
Labels
4 - In Review A fix for the issue is submitted for review. Area-Compilers Feature - Function Pointers Adding Function Pointers
Milestone

Comments

@KyouyamaKazusa0805
Copy link

Version Used:

VS 16.9 Preview 2

Steps to Reproduce:

Type code

#nullable enable

using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

unsafe
{
    string s = new StringBuilder()
        .AppendRange<int, string>(Enumerable.Range(1, 10), &converter) // Here.
        .ToString();
    
    Console.WriteLine(s);
}

static string converter(int v) => $"{v}, ";

public static class C
{
    public static unsafe StringBuilder AppendRange<TElement, TOther>(
        this StringBuilder @this,
        IEnumerable<TElement?> contentList,
        delegate*<TElement?, TOther?> converter)
    {
        foreach (var content in contentList)
        {
            @this.Append(converter(content)?.ToString() ?? string.Empty);
        }

        return @this;
    }
}

The code segment

string s = new StringBuilder()
    .AppendRange<int, string>(Enumerable.Range(1, 10), &converter) // Here.
    .ToString();

should specify type parameters <int, string>.

Expected Behavior:

Because of the type parameters can be inferred from function pointers, so we can omit them:

string s = new StringBuilder()
    .AppendRange(Enumerable.Range(1, 10), &converter)
    .ToString();

Actual Behavior:

An compiler error CS0411 raised: Try to specify type parameters.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Dec 22, 2020
@sharwell sharwell added the Feature - Function Pointers Adding Function Pointers label Dec 22, 2020
@jcouv
Copy link
Member

jcouv commented Dec 30, 2020

Doesn't repro on latest build (sharplab). I think this was fixed in PR #43041. But that PR pre-dates 16.9p2, so I may be missing something.

@333fred can you confirm and close if appropriate?

@jcouv jcouv added this to the 16.9 milestone Dec 30, 2020
@jcouv jcouv removed the untriaged Issues and PRs which have not yet been triaged by a lead label Dec 30, 2020
@333fred
Copy link
Member

333fred commented Dec 30, 2020

I cannot reproduce this on VS 16.9 Preview 2 with the code snippet provided, and this project file:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
  </PropertyGroup>

</Project>

@SunnieShine, is there anything else special about your environment?

@333fred 333fred added the Resolution-Not Reproducible The described behavior could not be reproduced by developers label Jan 4, 2021
@333fred
Copy link
Member

333fred commented Jan 4, 2021

@SunnieShine I've been unable to replicate this issue, and am closing it out. If you have more info, please comment and we can reopen.

@333fred 333fred closed this as completed Jan 4, 2021
@333fred
Copy link
Member

333fred commented Jan 4, 2021

Hmm, actually, the original snippet has the type parameters there, I misread it. I can reproduce it if I modify the snippet.

@333fred 333fred reopened this Jan 4, 2021
@jaredpar jaredpar removed the Resolution-Not Reproducible The described behavior could not be reproduced by developers label Jan 4, 2021
333fred added a commit to 333fred/roslyn that referenced this issue Jan 5, 2021
dotnet#43041 implemented exact inference of function pointer parameters and bounds only, and left a few errors in our tests that needed to be handled. This is also the cause of dotnet#50096. This implements bounds inference, using the same variance rules that function pointer to function pointer conversions do. I still need to spec the rules here, and may need to make a couple of adjustments around handling of delegate*->void* in bounds inference. At least initially, this isn't supported, but I'll work out what the correct rules should be when I spec it and update this PR accordingly.

Fixes dotnet#50096.
@333fred 333fred added the 4 - In Review A fix for the issue is submitted for review. label Jan 5, 2021
@KyouyamaKazusa0805
Copy link
Author

KyouyamaKazusa0805 commented Jan 5, 2021

@333fred I'm so sorry for late to read your reply. The real problem is that the type parameters can't be omitted.

To be honest, I have the same configuration with yours:

<PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <Nullable>enable</Nullable>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
    <LangVersion>9.0</LangVersion>
</PropertyGroup>

Snapshots:

Correct case:
Correct-case

Wrong case:
Wrong-case

@333fred
Copy link
Member

333fred commented Jan 5, 2021

As I mentioned, I misread your initial snippet. I have a draft out now that should fix the issue.

@KyouyamaKazusa0805
Copy link
Author

:)

@333fred
Copy link
Member

333fred commented Jan 29, 2021

Fixed in #50249

@333fred 333fred closed this as completed Jan 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4 - In Review A fix for the issue is submitted for review. Area-Compilers Feature - Function Pointers Adding Function Pointers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants