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

Error when same C type is imported twice and the type is extended by one of the modules #75336

Open
vinocher-bc opened this issue Jul 18, 2024 · 0 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@vinocher-bc
Copy link

Description

The attached test imports two C modules, both of which define the same C type (enum __x_ABI_CWindows_CGraphics_CImaging_CBitmapPixelFormat). One of the modules extends that type, but the other does not. A compiler error occurs when the extended type is accessed, presumably because the compiler doesn't recognize the existence of the extension.

Build the attached minimal repro sample:
cmake -S . -B build -G Ninja
cmake --build build

A compiler error occurs, which should not:

main.swift:11:42: error: type 'BitmapPixelFormat' (aka '__x_ABI_CWindows_CGraphics_CImaging_CBitmapPixelFormat') has no member 'bgra8'

Reproduction

Repro: swiftImportTest.zip

Excerpts:
C Type being imported using InteropTest and InteropTest2 modules:

enum __x_ABI_CWindows_CGraphics_CImaging_CBitmapPixelFormat
{
:
    __x_ABI_CWindows_CGraphics_CImaging_CBitmapPixelFormat_Bgra8 = 87,
:
};

ModuleTest extends the C type:

import InteropTest

public typealias BitmapPixelFormat = __x_ABI_CWindows_CGraphics_CImaging_CBitmapPixelFormat

extension ModuleTest.BitmapPixelFormat {
    public static var bgra8 : ModuleTest.BitmapPixelFormat {
        __x_ABI_CWindows_CGraphics_CImaging_CBitmapPixelFormat_Bgra8
    }
}

ModuleTest2 does not extend the C type:

import InteropTest2

Use of type:

import ModuleTest
import ModuleTest2

func main() {
    // Compile error: type 'BitmapPixelFormat' (aka '__x_ABI_CWindows_CGraphics_CImaging_CBitmapPixelFormat') has no member 'bgra8'
    let y = ModuleTest.BitmapPixelFormat.bgra8
    print("Format: \(y)")
}   

Expected behavior

This code should compile successfully.

Environment

compnerd.org Swift version 6.0-dev (LLVM a527f49f462b0d7, Swift eef85a7)
Target: x86_64-unknown-windows-msvc

Additional information

No response

@vinocher-bc vinocher-bc added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Jul 18, 2024
@hyp hyp self-assigned this Jul 18, 2024
@vinocher-bc vinocher-bc changed the title Error when same C type is imported twice and and the type is extended by one of the modules Error when same C type is imported twice and the type is extended by one of the modules Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

2 participants