Skip to content

Commit

Permalink
No errors for non-virtual members overrides (#14263)
Browse files Browse the repository at this point in the history
* No errors for non virtual members overrides

* Check for isFSharpObjModelTy as we are interested on csharp virtual methods

* More testing

* Add a feature lang preview

* More testing

* Fix PR comment
  • Loading branch information
edgarfgp authored Nov 13, 2022
1 parent b9d1bc3 commit e2f3a3e
Show file tree
Hide file tree
Showing 18 changed files with 512 additions and 7 deletions.
25 changes: 19 additions & 6 deletions src/Compiler/Checking/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10950,7 +10950,7 @@ and ComputeIsComplete enclosingDeclaredTypars declaredTypars ty =
/// Determine if a uniquely-identified-abstract-slot exists for an override member (or interface member implementation) based on the information available
/// at the syntactic definition of the member (i.e. prior to type inference). If so, we know the expected signature of the override, and the full slotsig
/// it implements. Apply the inferred slotsig.
and ApplyAbstractSlotInference (cenv: cenv) (envinner: TcEnv) (argsAndRetTy, m, synTyparDecls, declaredTypars, memberId, tcrefObjTy, renaming, _objTy, intfSlotTyOpt, valSynData, memberFlags: SynMemberFlags, attribs) =
and ApplyAbstractSlotInference (cenv: cenv) (envinner: TcEnv) (baseValOpt: Val option) (argsAndRetTy, m, synTyparDecls, declaredTypars, memberId, tcrefObjTy, renaming, intfSlotTyOpt, valSynData, memberFlags: SynMemberFlags, attribs) =

let g = cenv.g
let ad = envinner.eAccessRights
Expand Down Expand Up @@ -10997,7 +10997,21 @@ and ApplyAbstractSlotInference (cenv: cenv) (envinner: TcEnv) (argsAndRetTy, m,
| _ -> [] // check that method to override is sealed is located at CheckOverridesAreAllUsedOnce (typrelns.fs)
// We hit this case when it is ambiguous which abstract method is being implemented.


if g.langVersion.SupportsFeature(LanguageFeature.ErrorForNonVirtualMembersOverrides) then
// Checks if the declaring type inherits from a base class and is not FSharpObjModelTy
// Raises an error if we try to override an non virtual member with the same name in both
match baseValOpt with
| Some ttype when not(isFSharpObjModelTy g ttype.Type) ->
match stripTyEqns g ttype.Type with
| TType_app(tyconRef, _, _) ->
let ilMethods = tyconRef.ILTyconRawMetadata.Methods.AsList()
let nameOpt = ilMethods |> List.tryFind(fun id -> id.Name = memberId.idText)
match nameOpt with
| Some name when not name.IsVirtual ->
errorR(Error(FSComp.SR.tcNoMemberFoundForOverride(), memberId.idRange))
| _ -> ()
| _ -> ()
| _ -> ()

// If we determined a unique member then utilize the type information from the slotsig
let declaredTypars =
Expand Down Expand Up @@ -11159,14 +11173,14 @@ and AnalyzeRecursiveStaticMemberOrValDecl
CheckForNonAbstractInterface declKind tcref memberFlags id.idRange

let isExtrinsic = (declKind = ExtrinsicExtensionBinding)
let tcrefObjTy, enclosingDeclaredTypars, renaming, objTy, _ = FreshenObjectArgType cenv mBinding TyparRigidity.WillBeRigid tcref isExtrinsic declaredTyconTypars
let tcrefObjTy, enclosingDeclaredTypars, renaming, _, _ = FreshenObjectArgType cenv mBinding TyparRigidity.WillBeRigid tcref isExtrinsic declaredTyconTypars
let envinner = AddDeclaredTypars CheckForDuplicateTypars enclosingDeclaredTypars envinner
let envinner = MakeInnerEnvForTyconRef envinner tcref isExtrinsic

let (ExplicitTyparInfo(_, declaredTypars, infer)) = explicitTyparInfo

let optInferredImplSlotTys, declaredTypars =
ApplyAbstractSlotInference cenv envinner (ty, mBinding, synTyparDecls, declaredTypars, id, tcrefObjTy, renaming, objTy, intfSlotTyOpt, valSynInfo, memberFlags, bindingAttribs)
ApplyAbstractSlotInference cenv envinner None (ty, mBinding, synTyparDecls, declaredTypars, id, tcrefObjTy, renaming, intfSlotTyOpt, valSynInfo, memberFlags, bindingAttribs)

let explicitTyparInfo = ExplicitTyparInfo(declaredTypars, declaredTypars, infer)

Expand Down Expand Up @@ -11231,7 +11245,6 @@ and AnalyzeRecursiveStaticMemberOrValDecl
| _ ->
envinner, tpenv, id, None, None, vis, vis2, None, [], None, explicitTyparInfo, bindingRhs, declaredTypars


and AnalyzeRecursiveInstanceMemberDecl
(cenv: cenv,
envinner: TcEnv,
Expand Down Expand Up @@ -11290,7 +11303,7 @@ and AnalyzeRecursiveInstanceMemberDecl
// at the member signature. If so, we know the type of this member, and the full slotsig
// it implements. Apply the inferred slotsig.
let optInferredImplSlotTys, declaredTypars =
ApplyAbstractSlotInference cenv envinner (argsAndRetTy, mBinding, synTyparDecls, declaredTypars, memberId, tcrefObjTy, renaming, objTy, intfSlotTyOpt, valSynInfo, memberFlags, bindingAttribs)
ApplyAbstractSlotInference cenv envinner baseValOpt (argsAndRetTy, mBinding, synTyparDecls, declaredTypars, memberId, tcrefObjTy, renaming, intfSlotTyOpt, valSynInfo, memberFlags, bindingAttribs)

// Update the ExplicitTyparInfo to reflect the declaredTypars inferred from the abstract slot
let explicitTyparInfo = ExplicitTyparInfo(declaredTypars, declaredTypars, infer)
Expand Down
1 change: 1 addition & 0 deletions src/Compiler/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1561,6 +1561,7 @@ featureInitProperties,"support for consuming init properties"
featureLowercaseDUWhenRequireQualifiedAccess,"Allow lowercase DU when RequireQualifiedAccess attribute"
featureMatchNotAllowedForUnionCaseWithNoData,"Pattern match discard is not allowed for union case that takes no data."
featureCSharpExtensionAttributeNotRequired,"Allow implicit Extension attribute on declaring types, modules"
featureErrorForNonVirtualMembersOverrides,"Raises errors for non-virtual members overrides"
3353,fsiInvalidDirective,"Invalid directive '#%s %s'"
3354,tcNotAFunctionButIndexerNamedIndexingNotYetEnabled,"This value supports indexing, e.g. '%s.[index]'. The syntax '%s[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation."
3354,tcNotAFunctionButIndexerIndexingNotYetEnabled,"This expression supports indexing, e.g. 'expr.[index]'. The syntax 'expr[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation."
Expand Down
3 changes: 3 additions & 0 deletions src/Compiler/Facilities/LanguageFeatures.fs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type LanguageFeature =
| SelfTypeConstraints
| MatchNotAllowedForUnionCaseWithNoData
| CSharpExtensionAttributeNotRequired
| ErrorForNonVirtualMembersOverrides

/// LanguageVersion management
type LanguageVersion(versionText) =
Expand Down Expand Up @@ -128,6 +129,7 @@ type LanguageVersion(versionText) =
LanguageFeature.FromEndSlicing, previewVersion
LanguageFeature.MatchNotAllowedForUnionCaseWithNoData, previewVersion
LanguageFeature.CSharpExtensionAttributeNotRequired, previewVersion
LanguageFeature.ErrorForNonVirtualMembersOverrides, previewVersion

]

Expand Down Expand Up @@ -237,6 +239,7 @@ type LanguageVersion(versionText) =
| LanguageFeature.SelfTypeConstraints -> FSComp.SR.featureSelfTypeConstraints ()
| LanguageFeature.MatchNotAllowedForUnionCaseWithNoData -> FSComp.SR.featureMatchNotAllowedForUnionCaseWithNoData ()
| LanguageFeature.CSharpExtensionAttributeNotRequired -> FSComp.SR.featureCSharpExtensionAttributeNotRequired ()
| LanguageFeature.ErrorForNonVirtualMembersOverrides -> FSComp.SR.featureErrorForNonVirtualMembersOverrides ()

/// Get a version string associated with the given feature.
static member GetFeatureVersionString feature =
Expand Down
1 change: 1 addition & 0 deletions src/Compiler/Facilities/LanguageFeatures.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type LanguageFeature =
| SelfTypeConstraints
| MatchNotAllowedForUnionCaseWithNoData
| CSharpExtensionAttributeNotRequired
| ErrorForNonVirtualMembersOverrides

/// LanguageVersion management
type LanguageVersion =
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@
<target state="translated">literál float32 bez tečky</target>
<note />
</trans-unit>
<trans-unit id="featureErrorForNonVirtualMembersOverrides">
<source>Raises errors for non-virtual members overrides</source>
<target state="new">Raises errors for non-virtual members overrides</target>
<note />
</trans-unit>
<trans-unit id="featureErrorOnDeprecatedRequireQualifiedAccess">
<source>give error on deprecated access of construct with RequireQualifiedAccess attribute</source>
<target state="translated">chyba při zastaralém přístupu konstruktoru s atributem RequireQualifiedAccess</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@
<target state="translated">punktloses float32-Literal</target>
<note />
</trans-unit>
<trans-unit id="featureErrorForNonVirtualMembersOverrides">
<source>Raises errors for non-virtual members overrides</source>
<target state="new">Raises errors for non-virtual members overrides</target>
<note />
</trans-unit>
<trans-unit id="featureErrorOnDeprecatedRequireQualifiedAccess">
<source>give error on deprecated access of construct with RequireQualifiedAccess attribute</source>
<target state="translated">Beim veralteten Zugriff auf das Konstrukt mit dem RequireQualifiedAccess-Attribut wird ein Fehler ausgegeben.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@
<target state="translated">literal float32 sin punto</target>
<note />
</trans-unit>
<trans-unit id="featureErrorForNonVirtualMembersOverrides">
<source>Raises errors for non-virtual members overrides</source>
<target state="new">Raises errors for non-virtual members overrides</target>
<note />
</trans-unit>
<trans-unit id="featureErrorOnDeprecatedRequireQualifiedAccess">
<source>give error on deprecated access of construct with RequireQualifiedAccess attribute</source>
<target state="translated">error en el acceso en desuso de la construcción con el atributo RequireQualifiedAccess</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@
<target state="translated">littéral float32 sans point</target>
<note />
</trans-unit>
<trans-unit id="featureErrorForNonVirtualMembersOverrides">
<source>Raises errors for non-virtual members overrides</source>
<target state="new">Raises errors for non-virtual members overrides</target>
<note />
</trans-unit>
<trans-unit id="featureErrorOnDeprecatedRequireQualifiedAccess">
<source>give error on deprecated access of construct with RequireQualifiedAccess attribute</source>
<target state="translated">donner une erreur sur l’accès déconseillé de la construction avec l’attribut RequireQualifiedAccess</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@
<target state="translated">valore letterale float32 senza punti</target>
<note />
</trans-unit>
<trans-unit id="featureErrorForNonVirtualMembersOverrides">
<source>Raises errors for non-virtual members overrides</source>
<target state="new">Raises errors for non-virtual members overrides</target>
<note />
</trans-unit>
<trans-unit id="featureErrorOnDeprecatedRequireQualifiedAccess">
<source>give error on deprecated access of construct with RequireQualifiedAccess attribute</source>
<target state="translated">errore durante l'accesso deprecato del costrutto con l'attributo RequireQualifiedAccess</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@
<target state="translated">ドットなしの float32 リテラル</target>
<note />
</trans-unit>
<trans-unit id="featureErrorForNonVirtualMembersOverrides">
<source>Raises errors for non-virtual members overrides</source>
<target state="new">Raises errors for non-virtual members overrides</target>
<note />
</trans-unit>
<trans-unit id="featureErrorOnDeprecatedRequireQualifiedAccess">
<source>give error on deprecated access of construct with RequireQualifiedAccess attribute</source>
<target state="translated">RequireQualifiedAccess 属性を持つコンストラクトの非推奨アクセスでエラーが発生しました</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@
<target state="translated">점이 없는 float32 리터럴</target>
<note />
</trans-unit>
<trans-unit id="featureErrorForNonVirtualMembersOverrides">
<source>Raises errors for non-virtual members overrides</source>
<target state="new">Raises errors for non-virtual members overrides</target>
<note />
</trans-unit>
<trans-unit id="featureErrorOnDeprecatedRequireQualifiedAccess">
<source>give error on deprecated access of construct with RequireQualifiedAccess attribute</source>
<target state="translated">RequireQualifiedAccess 특성을 사용하여 사용되지 않는 구문 액세스에 대한 오류 제공</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@
<target state="translated">bezkropkowy literał float32</target>
<note />
</trans-unit>
<trans-unit id="featureErrorForNonVirtualMembersOverrides">
<source>Raises errors for non-virtual members overrides</source>
<target state="new">Raises errors for non-virtual members overrides</target>
<note />
</trans-unit>
<trans-unit id="featureErrorOnDeprecatedRequireQualifiedAccess">
<source>give error on deprecated access of construct with RequireQualifiedAccess attribute</source>
<target state="translated">wskazywanie błędu w przypadku przestarzałego dostępu do konstrukcji z atrybutem RequireQualifiedAccess</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.pt-BR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@
<target state="translated">literal float32 sem ponto</target>
<note />
</trans-unit>
<trans-unit id="featureErrorForNonVirtualMembersOverrides">
<source>Raises errors for non-virtual members overrides</source>
<target state="new">Raises errors for non-virtual members overrides</target>
<note />
</trans-unit>
<trans-unit id="featureErrorOnDeprecatedRequireQualifiedAccess">
<source>give error on deprecated access of construct with RequireQualifiedAccess attribute</source>
<target state="translated">fornecer erro no acesso preterido do constructo com o atributo RequireQualifiedAccess</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ru.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@
<target state="translated">литерал float32 без точки</target>
<note />
</trans-unit>
<trans-unit id="featureErrorForNonVirtualMembersOverrides">
<source>Raises errors for non-virtual members overrides</source>
<target state="new">Raises errors for non-virtual members overrides</target>
<note />
</trans-unit>
<trans-unit id="featureErrorOnDeprecatedRequireQualifiedAccess">
<source>give error on deprecated access of construct with RequireQualifiedAccess attribute</source>
<target state="translated">выдать ошибку при устаревшем доступе к конструкции с атрибутом RequireQualifiedAccess</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.tr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@
<target state="translated">noktasız float32 sabit değeri</target>
<note />
</trans-unit>
<trans-unit id="featureErrorForNonVirtualMembersOverrides">
<source>Raises errors for non-virtual members overrides</source>
<target state="new">Raises errors for non-virtual members overrides</target>
<note />
</trans-unit>
<trans-unit id="featureErrorOnDeprecatedRequireQualifiedAccess">
<source>give error on deprecated access of construct with RequireQualifiedAccess attribute</source>
<target state="translated">RequireQualifiedAccess özniteliğine sahip yapının kullanım dışı erişiminde hata</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.zh-Hans.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@
<target state="translated">无点 float32 文本</target>
<note />
</trans-unit>
<trans-unit id="featureErrorForNonVirtualMembersOverrides">
<source>Raises errors for non-virtual members overrides</source>
<target state="new">Raises errors for non-virtual members overrides</target>
<note />
</trans-unit>
<trans-unit id="featureErrorOnDeprecatedRequireQualifiedAccess">
<source>give error on deprecated access of construct with RequireQualifiedAccess attribute</source>
<target state="translated">对具有 RequireQualifiedAccess 属性的构造进行弃用的访问时出错</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.zh-Hant.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@
<target state="translated">無點號的 float32 常值</target>
<note />
</trans-unit>
<trans-unit id="featureErrorForNonVirtualMembersOverrides">
<source>Raises errors for non-virtual members overrides</source>
<target state="new">Raises errors for non-virtual members overrides</target>
<note />
</trans-unit>
<trans-unit id="featureErrorOnDeprecatedRequireQualifiedAccess">
<source>give error on deprecated access of construct with RequireQualifiedAccess attribute</source>
<target state="translated">對具有 RequireQualifiedAccess 屬性的建構的已取代存取發出錯誤</target>
Expand Down
Loading

0 comments on commit e2f3a3e

Please sign in to comment.