Skip to content

Support 'protected abstract' #12281

Description

@kostya9

Repro steps

  1. Create new fsharp project
  2. Add "MarkdigExtensions.SyntaxHighlighting" package
  3. Add the following code
open Markdig.Renderers
open Markdig.Renderers.Html
open Markdig.Syntax
open MarkdigExtensions.SyntaxHighlighting


type SyntaxHighlightingRendererWrapper() =
    inherit CodeBlockRenderer() with
        let highlightingRenderer = HighlightedCodeBlockRenderer()

        override _.Write(renderer: HtmlRenderer, codeBlock: CodeBlock): unit =
            highlightingRenderer.Write(renderer, codeBlock)

ZIP archive of the reproduction:
Repro_fsharp_accessibility.zip

Expected behavior

No compilation errors

Actual behavior

Error

  Program.fs(12, 13): [FS0629] Method 'Write' is not accessible from this code location

Known workarounds

Extract Write method into a function:

open Markdig.Renderers
open Markdig.Renderers.Html
open Markdig.Syntax
open MarkdigExtensions.SyntaxHighlighting


let render (highlightingRenderer: HighlightedCodeBlockRenderer) (renderer: HtmlRenderer) (codeBlock: CodeBlock) =
    highlightingRenderer.Write(renderer, codeBlock)

type SyntaxHighlightingRendererWrapper() =
    inherit CodeBlockRenderer() with
        let highlightingRenderer = HighlightedCodeBlockRenderer()

        override _.Write(renderer: HtmlRenderer, codeBlock: CodeBlock): unit =
            render highlightingRenderer renderer codeBlock

Related information

  • Win11
  • .NET 6 (SDK version=6.0.100-rc.2.21505.57)
  • Building via dotnet CLI (dotnet build)

I can only guess that this has something to do with overload resolution.
Type HighlightedCodeBlockRenderer inherits from MarkdownObjectRenderer that has a similar protected method:

protected abstract void Write(TRenderer renderer, TObject obj);
// TRenderer resolves into HtmlRenderer
// TObject resolves into CodeBlock

Activity

  1. dsyme commented on Oct 19, 2021

    @dsyme
    Contributor

    That use of with is unusual. Could you try this?

    type SyntaxHighlightingRendererWrapper() =
        inherit CodeBlockRenderer()
        let highlightingRenderer = HighlightedCodeBlockRenderer()
    
        override _.Write(renderer: HtmlRenderer, codeBlock: CodeBlock): unit =
            highlightingRenderer.Write(renderer, codeBlock)

    I think the issue is related to protected - Could you link the exact definitions of the virtual Write method please?

  2. kostya9 commented on Oct 22, 2021

    @kostya9
    ContributorAuthor

    Sure, tried with the syntax without with, the problem unfortunately persists.

    Overload resolution

    Did some additional investigation.

    With the Write inlined, the overload taken is

    override HighlightedCodeBlockRenderer.Write : renderer:HtmlRenderer * cb:CodeBlock -> unit

    With the Write in a separate render function, the overload is:

    MarkdownObjectRenderer.Write(renderer: RendererBase, obj: MarkdownObject) : unit

    Seems like the overload resolution somehow changes depending on the context?

    Method in inheritance hierarchy

    Here are the exact definitions of the Write method in the inheritance hierarchy:

    HighlightedCodeBlockRenderer

    override __.Write(renderer : HtmlRenderer, cb : CodeBlock)

    inherits from CodeBlockRenderer

    protected override void Write(HtmlRenderer renderer, CodeBlock obj)

    inherits from HtmlObjectRenderer<CodeBlock>
    inherits from MarkdownObjectRenderer<HtmlRenderer, TObject> where TObject : MarkdownObject

    public virtual void Write(RendererBase renderer, MarkdownObject obj);
    protected abstract void Write(TRenderer renderer, TObject obj);
  3. added
    Impact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.
    Impact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.
    and removed
    Impact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.
    on Mar 3, 2022
  4. changed the title [-]Compilation Error - Inaccessible method[/-] [+]Support 'protected abstract'[/+] on Apr 5, 2022
  5. added this to the Backlog milestone on Oct 19, 2022
  6. github-actions commented on Oct 9, 2026

    @github-actions
    Contributor

    🤖 This is an automated response from Repo Assist.

    I reproduced this on current main at fc10369a668762034e27b82451f469321d878009 (commit timestamp 2026-10-08 15:17:21 UTC, about 10 hours old at test time). The repository-built FSI reports:

    Microsoft (R) F# Interactive version 15.2.200.0 for F# 11.2
    Language Version: 11.2
    FSharp.Core: 11.0.0.0
    .NET: .NET 11.0.0-rc.1.26420.103
    

    Using MarkdigExtensions.SyntaxHighlighting 1.0.3 and the issue reproduction unchanged, I compiled with the repository-built artifacts/bin/fsc/Proto/net11.0/linux-x64/fsc.dll. It still fails at highlightingRenderer.Write(renderer, codeBlock):

    Program.fs(12,30): error FS0629: Method 'Write' is not accessible from this code location
    

    The extracted-function workaround still distinguishes the scenario described here, so the original protected-overload accessibility issue remains reproducible on the latest compiler.

    Warning

    Firewall blocked 1 domain

    The following domain was blocked by the firewall during workflow execution:

    • southcentralus0.in.applicationinsights.azure.com

    To allow these domains, add them to the network.allowed list in your workflow frontmatter:

    network:
      allowed:
        - defaults
        - "southcentralus0.in.applicationinsights.azure.com"

    See Network Configuration for more information.

    Generated by 🌈 Repo Assist, see workflow run. Learn more.

    Add this agentic workflows to your repo

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/repo-assist.md@7c7feb61a52b662eb2089aa2945588b7a200d404
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Compiler-ImportAndInteropimport of .NET DLLs and interopBugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.

    Type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions