Skip to content

Commit 1bdcf1a

Browse files
Edgar GonzalezEdgar Gonzalez
Edgar Gonzalez
authored and
Edgar Gonzalez
committed
isCompileGenerated
1 parent bd46376 commit 1bdcf1a

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/Compiler/Checking/PostInferenceChecks.fs

+13-6
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ let AccessInternalsVisibleToAsInternal thisCompPath internalsVisibleToPaths acce
521521
accessSubstPaths (thisCompPath, internalsVisibleToPath) access)
522522

523523

524-
let CheckTypeForAccess (cenv: cenv) env objName valAcc m ty =
524+
let CheckTypeForAccess (cenv: cenv) env objName valAcc isCompilerGenerated m ty =
525525
if cenv.reportErrors then
526526

527527
let visitType ty =
@@ -532,8 +532,14 @@ let CheckTypeForAccess (cenv: cenv) env objName valAcc m ty =
532532
| ValueSome tcref ->
533533
let thisCompPath = compPathOfCcu cenv.viewCcu
534534
let tyconAcc = tcref.Accessibility |> AccessInternalsVisibleToAsInternal thisCompPath cenv.internalsVisibleToPaths
535-
536-
if isLessAccessible tyconAcc valAcc then
535+
536+
// Skip accessibility checks for compiler-generated pattern inputs, which all have names
537+
// starting with "val patternInput". This allows pattern matching to work properly with private
538+
// types when the pattern is used within the same module scope.
539+
// let isCompilerGeneratedPatternInput =
540+
// let name: string = objName()
541+
// name.StartsWith("val patternInput")
542+
if not isCompilerGenerated && isLessAccessible tyconAcc valAcc then
537543
errorR(Error(FSComp.SR.chkTypeLessAccessibleThanType(tcref.DisplayName, objName()), m))
538544

539545
CheckTypeDeep cenv (visitType, None, None, None, None) cenv.g env NoInfo ty
@@ -2058,7 +2064,8 @@ and CheckBinding cenv env alwaysCheckNoReraise ctxt (TBind(v, bindRhs, _) as bin
20582064

20592065
// Check accessibility
20602066
if (v.IsMemberOrModuleBinding || v.IsMember) && not v.IsIncrClassGeneratedMember then
2061-
CheckTypeForAccess cenv env (fun () -> NicePrint.stringOfQualifiedValOrMember cenv.denv cenv.infoReader vref) vref.Accessibility v.Range v.Type
2067+
let access = AdjustAccess (IsHiddenVal env.sigToImplRemapInfo v) (fun () -> v.DeclaringEntity.CompilationPath) v.Accessibility
2068+
CheckTypeForAccess cenv env (fun () -> NicePrint.stringOfQualifiedValOrMember cenv.denv cenv.infoReader vref) access vref.IsCompilerGenerated v.Range v.Type
20622069

20632070
if cenv.reportErrors then
20642071

@@ -2283,7 +2290,7 @@ let CheckRecdField isUnion cenv env (tycon: Tycon) (rfield: RecdField) =
22832290
IsHiddenTyconRepr env.sigToImplRemapInfo tycon ||
22842291
(not isUnion && IsHiddenRecdField env.sigToImplRemapInfo (tcref.MakeNestedRecdFieldRef rfield))
22852292
let access = AdjustAccess isHidden (fun () -> tycon.CompilationPath) rfield.Accessibility
2286-
CheckTypeForAccess cenv env (fun () -> rfield.LogicalName) access m fieldTy
2293+
CheckTypeForAccess cenv env (fun () -> rfield.LogicalName) access false m fieldTy
22872294

22882295
if isByrefLikeTyconRef g m tcref then
22892296
// Permit Span fields in IsByRefLike types
@@ -2551,7 +2558,7 @@ let CheckEntityDefn cenv env (tycon: Entity) =
25512558

25522559
// Access checks
25532560
let access = AdjustAccess (IsHiddenTycon env.sigToImplRemapInfo tycon) (fun () -> tycon.CompilationPath) tycon.Accessibility
2554-
let visitType ty = CheckTypeForAccess cenv env (fun () -> tycon.DisplayNameWithStaticParametersAndUnderscoreTypars) access tycon.Range ty
2561+
let visitType ty = CheckTypeForAccess cenv env (fun () -> tycon.DisplayNameWithStaticParametersAndUnderscoreTypars) access false tycon.Range ty
25552562

25562563
abstractSlotValsOfTycons [tycon] |> List.iter (typeOfVal >> visitType)
25572564

0 commit comments

Comments
 (0)