@@ -521,7 +521,7 @@ let AccessInternalsVisibleToAsInternal thisCompPath internalsVisibleToPaths acce
521
521
accessSubstPaths ( thisCompPath, internalsVisibleToPath) access)
522
522
523
523
524
- let CheckTypeForAccess ( cenv : cenv ) env objName valAcc m ty =
524
+ let CheckTypeForAccess ( cenv : cenv ) env objName valAcc isCompilerGenerated m ty =
525
525
if cenv.reportErrors then
526
526
527
527
let visitType ty =
@@ -532,8 +532,14 @@ let CheckTypeForAccess (cenv: cenv) env objName valAcc m ty =
532
532
| ValueSome tcref ->
533
533
let thisCompPath = compPathOfCcu cenv.viewCcu
534
534
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
537
543
errorR( Error( FSComp.SR.chkTypeLessAccessibleThanType( tcref.DisplayName, objName()), m))
538
544
539
545
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
2058
2064
2059
2065
// Check accessibility
2060
2066
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
2062
2069
2063
2070
if cenv.reportErrors then
2064
2071
@@ -2283,7 +2290,7 @@ let CheckRecdField isUnion cenv env (tycon: Tycon) (rfield: RecdField) =
2283
2290
IsHiddenTyconRepr env.sigToImplRemapInfo tycon ||
2284
2291
( not isUnion && IsHiddenRecdField env.sigToImplRemapInfo ( tcref.MakeNestedRecdFieldRef rfield))
2285
2292
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
2287
2294
2288
2295
if isByrefLikeTyconRef g m tcref then
2289
2296
// Permit Span fields in IsByRefLike types
@@ -2551,7 +2558,7 @@ let CheckEntityDefn cenv env (tycon: Entity) =
2551
2558
2552
2559
// Access checks
2553
2560
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
2555
2562
2556
2563
abstractSlotValsOfTycons [ tycon] |> List.iter ( typeOfVal >> visitType)
2557
2564
0 commit comments