Xcode shows compiler errors when accessing class properties and methods only when class is in separate file

When building the code below, two compiler errors appear in AppDelegate.swift:

Value of type 'Slice<MyCollection<MySubCollection>>' has no member 'url'

No exact matches in call to instance method 'remove'

When moving the first 2 classes in ViewController.swift to AppDelegate.swift, the issues go away. Is this expected, or a bug?

//  AppDelegate.swift
//

import Cocoa

@main
class AppDelegate: NSObject, NSApplicationDelegate {

    func applicationDidFinishLaunching(_ aNotification: Notification) {
        var collection: MyCollection<MySubCollection>!
        let a = collection.first!.url!
        var subCollection: MySubCollection!
        collection.remove(subCollection)
    }

}
//
//  ViewController.swift
//

import Cocoa

class MyCollection<Element>: MyCollectionProtocol {
    
    var elements = [Element]()
    
}

class MySubCollection: MyCollectionProtocol {
    
    var elements = [String]()
    var url: URL?
    
}

protocol MyCollectionProtocol: AnyObject, Collection where Index == Int {
    associatedtype Element
    var elements: [Element] { get set }
}

extension MyCollectionProtocol {
    
    var startIndex: Index {
        return elements.startIndex
    }

    var endIndex: Index {
        return elements.endIndex
    }

    subscript(position: Index) -> Element {
        return elements[position]
    }

    func index(after i: Index) -> Index {
        return elements.index(after: i)
    }
    
}

extension MyCollectionProtocol where Element == String {
    
    func remove(_ element: Element) {
    }
    
}

extension MyCollectionProtocol where Element: MyCollectionProtocol {
    
    func remove(_ element: Element) {
    }
    
}

Did you show the whole code of ViewController ?

Yes, that's the entire code in the project.

Xcode shows compiler errors when accessing class properties and methods only when class is in separate file
 
 
Q