Files
swift-mirror/userdocs/diagnostics/member-import-visibility.md
Ben Barham 32ec5a61b7 Add groupings for the various diagnostics
Also make the titles and one line summaries a little more consistent (at
least for diagnsotic groups and upcoming language features, haven't gone
through the educational notes).
2025-06-05 15:49:46 -07:00

1.1 KiB

Member import visibility (MemberImportVisibility)

Enables errors for uses of members that cannot be accessed because their defining module is not directly imported.

Overview

Prior to enabling this feature, it was possible to use a member if it was declared in a module that was transitively imported. MemberImportVisibility unifies the visibility rules for members to match those of top-level, such that only members contained in a direct import are visible:

func getFileContents() throws -> String {
  // error: initializer 'init(contentsOfFile:)' is not available due to missing import of defining module 'Foundation'
  return try String(contentsOfFile: "example.txt")
}

To resolve the error, add an import of the module that defines the member.

Migration

-enable-upcoming-feature MemberImportVisibility:migrate

Enabling migration for MemberImportVisibility adds fix-its for the missing modules, i.e. those that declare members used in the file and are not directly imported.

See also