summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2025-07-22 16:14:07 -0700
committerGitHub <noreply@github.com>2025-07-22 23:14:07 +0000
commit165a95ebb2e9dbdc1b92bdc103470438a5114500 (patch)
tree31318fc5633d5596c5ed3c7c910e690d9fd6ca8f /source
parent8a36695f1f3abaf98831d4512e74ebd5bce1494e (diff)
Fix visibility of synthesized Differential typedefs. (#7865)
* Fix visibility of synthesized `Differential` typedefs. * Delete incorrect test.
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-check-decl.cpp40
1 files changed, 18 insertions, 22 deletions
diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp
index 806912abe..cebe1bb00 100644
--- a/source/slang/slang-check-decl.cpp
+++ b/source/slang/slang-check-decl.cpp
@@ -2988,6 +2988,8 @@ bool SemanticsVisitor::trySynthesizeDifferentialAssociatedTypeRequirementWitness
assocTypeDef->type.type = context->conformingType;
context->parentDecl->addMember(assocTypeDef);
assocTypeDef->setCheckState(DeclCheckState::DefinitionChecked);
+ auto visibility = getDeclVisibility(context->parentDecl);
+ addVisibilityModifier(assocTypeDef, visibility);
markSelfDifferentialMembersOfType(
as<AggTypeDecl>(context->parentDecl),
@@ -3022,6 +3024,10 @@ bool SemanticsVisitor::trySynthesizeDifferentialAssociatedTypeRequirementWitness
aggTypeDecl->nameAndLoc.name = requirementDeclRef.getName();
aggTypeDecl->loc = context->parentDecl->nameAndLoc.loc;
+ // The visibility of synthesized decl should be the same of the parent decl.
+ auto thisVisibility = getDeclVisibility(context->parentDecl);
+ addVisibilityModifier(aggTypeDecl, thisVisibility);
+
context->parentDecl->addDirectMemberDecl(aggTypeDecl);
synth.pushScopeForContainer(aggTypeDecl);
}
@@ -3144,7 +3150,8 @@ bool SemanticsVisitor::trySynthesizeDifferentialAssociatedTypeRequirementWitness
assocTypeDef->nameAndLoc.name = differentialName;
assocTypeDef->type.type = satisfyingType;
assocTypeDef->setCheckState(DeclCheckState::DefinitionChecked);
-
+ auto visibility = getDeclVisibility(aggTypeDecl);
+ addVisibilityModifier(assocTypeDef, visibility);
aggTypeDecl->addDirectMemberDecl(assocTypeDef);
}
@@ -3176,9 +3183,6 @@ bool SemanticsVisitor::trySynthesizeDifferentialAssociatedTypeRequirementWitness
addModifier(aggTypeDecl, m_astBuilder->create<SynthesizedModifier>());
- // The visibility of synthesized decl should be the same of the parent decl.
- auto thisVisibility = getDeclVisibility(context->parentDecl);
- addVisibilityModifier(aggTypeDecl, thisVisibility);
// Synthesize the rest of IDifferential method conformances by recursively checking
// conformance on the synthesized decl.
@@ -7483,25 +7487,17 @@ bool SemanticsVisitor::findWitnessForInterfaceRequirement(
if (doesMemberSatisfyRequirement(member.declRef, requiredMemberDeclRef, witnessTable))
{
- // The member satisfies the requirement in every other way except that
- // it may have a lower visibility than min(parentVisibility, requirementVisibilty),
- // in that case we will treat it as an error.
- auto minRequiredVisibility = Math::Min(
- getDeclVisibility(requiredMemberDeclRef.getDecl()),
- getTypeVisibility(subType));
- if (getDeclVisibility(member.declRef.getDecl()) < minRequiredVisibility)
- {
- getSink()->diagnose(
- member.declRef,
- Diagnostics::satisfyingDeclCannotHaveLowerVisibility,
- member.declRef);
- getSink()->diagnose(
- requiredMemberDeclRef,
- Diagnostics::seeDeclarationOf,
- QualifiedDeclPath(requiredMemberDeclRef));
- return false;
- }
+ // The member satisfies the requirement, so we should add an `IsOverriding`
+ // modifier to the decl, to enable us to verify if a method with `override` keyword
+ // is actually overriding something.
markOverridingDecl(context, member.declRef.getDecl(), requiredMemberDeclRef);
+
+ // Note: we do not impose any additional requirement on the visibility of the member.
+ // Specifically, it is valid for a method with lower visibility to implement an
+ // interface requirement that has higher visibility. It simply means the method is
+ // only accessible externally from the interface and not directly from the concrete
+ // type.
+ //
return true;
}
}