Skip to content

InvalidProgramException on string interpolation #17719

Closed

Description

@bent-rasmussen

Please provide a succinct description of the issue.

Repro steps

Provide the steps required to reproduce the problem:

  1. Create a console project with this code
type Foo() =

    let sb = System.Text.StringBuilder()

    member _.Bar(s: System.ReadOnlySpan<char>) = sb.Append(s) |> ignore

let foo = Foo()
let foos = "foo"
foo.Bar($"{foos} is bar")
  1. Build and run the project

Expected behavior

InvalidProgramException

Actual behavior

InvalidProgramException

Known workarounds

  • Use let binding for interpolated string and use that in function call
  • Use string instead of ReadOnlySpan<char>
  • Do not use string interpolation

Related information

Provide any related information (optional):

  • Windows 11
  • .NET 9 RC1
  • Version 17.12.0 Preview 2.0

Activity

  1. added this to the Backlog milestone on Sep 13, 2024
  2. vzarytovskii commented on Sep 13, 2024

    @vzarytovskii
    Member

    Yes, we should probably disallow byreflikes when we work with interpolation until we have good escape analysis.

  3. vzarytovskii commented on Sep 13, 2024

    @vzarytovskii
    Member

    Also <LangVersion>8</LangVersion> fixes it

  4. added a commit that references this issue on Sep 13, 2024
    00a8ee9
  5. added a commit that references this issue on Sep 13, 2024
    c910057
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions