diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index 332cea09879..24c444664fd 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -4358,12 +4358,13 @@ and TcTypeOrMeasure kindOpt (cenv: cenv) newOk checkConstraints occ (iwsam: Warn and CheckIWSAM (cenv: cenv) (env: TcEnv) checkConstraints iwsam m tcref = let g = cenv.g - let ad = env.eAccessRights let ty = generalizedTyconRef g tcref + if iwsam = WarnOnIWSAM.Yes && isInterfaceTy g ty && checkConstraints = CheckCxs then - let tcref = tcrefOfAppTy g ty - let meths = AllMethInfosOfTypeInScope ResultCollectionSettings.AllResults cenv.infoReader env.NameEnv None ad IgnoreOverrides m ty + let meths = AllMethInfosOfTypeInScope ResultCollectionSettings.AllResults cenv.infoReader env.NameEnv None env.eAccessRights IgnoreOverrides m ty + if meths |> List.exists (fun meth -> not meth.IsInstance && meth.IsDispatchSlot && not meth.IsExtensionMember) then + let tcref = tcrefOfAppTy g ty warning(Error(FSComp.SR.tcUsingInterfaceWithStaticAbstractMethodAsType(tcref.DisplayNameWithStaticParametersAndUnderscoreTypars), m)) and TcLongIdentType kindOpt (cenv: cenv) newOk checkConstraints occ iwsam env tpenv synLongId = @@ -11080,7 +11081,7 @@ and ApplyAbstractSlotInference (cenv: cenv) (envinner: TcEnv) (_: Val option) (a [], declaredTypars -and CheckForNonAbstractInterface declKind tcref (memberFlags: SynMemberFlags) m = +and CheckForNonAbstractInterface (g: TcGlobals) declKind tcref (memberFlags: SynMemberFlags) isMemberStatic m = if isInterfaceTyconRef tcref then if memberFlags.MemberKind = SynMemberKind.ClassConstructor then error(Error(FSComp.SR.tcStaticInitializersIllegalInInterface(), m)) @@ -11088,8 +11089,11 @@ and CheckForNonAbstractInterface declKind tcref (memberFlags: SynMemberFlags) m error(Error(FSComp.SR.tcObjectConstructorsIllegalInInterface(), m)) elif memberFlags.IsOverrideOrExplicitImpl then error(Error(FSComp.SR.tcMemberOverridesIllegalInInterface(), m)) - elif not (declKind=ExtrinsicExtensionBinding || memberFlags.IsDispatchSlot ) then - error(Error(FSComp.SR.tcConcreteMembersIllegalInInterface(), m)) + elif not (declKind = ExtrinsicExtensionBinding || memberFlags.IsDispatchSlot) then + if not isMemberStatic then + error(Error(FSComp.SR.tcConcreteMembersIllegalInInterface(), m)) + else + checkLanguageFeatureError g.langVersion LanguageFeature.StaticMembersInInterfaces m //------------------------------------------------------------------------- // TcLetrecBindings - AnalyzeAndMakeAndPublishRecursiveValue s @@ -11135,7 +11139,7 @@ and AnalyzeRecursiveStaticMemberOrValDecl memberFlags.IsOverrideOrExplicitImpl -> CheckMemberFlags intfSlotTyOpt newslotsOK overridesOK memberFlags id.idRange - CheckForNonAbstractInterface declKind tcref memberFlags id.idRange + CheckForNonAbstractInterface g declKind tcref memberFlags true id.idRange let isExtrinsic = (declKind = ExtrinsicExtensionBinding) let tcrefObjTy, enclosingDeclaredTypars, renaming, _, _ = FreshenObjectArgType cenv mBinding TyparRigidity.WillBeRigid tcref isExtrinsic declaredTyconTypars @@ -11157,7 +11161,7 @@ and AnalyzeRecursiveStaticMemberOrValDecl assert (Option.isNone intfSlotTyOpt) CheckMemberFlags None newslotsOK overridesOK memberFlags id.idRange - CheckForNonAbstractInterface declKind tcref memberFlags id.idRange + CheckForNonAbstractInterface g declKind tcref memberFlags true id.idRange if memberFlags.MemberKind = SynMemberKind.Constructor && tcref.Deref.IsFSharpException then error(Error(FSComp.SR.tcConstructorsDisallowedInExceptionAugmentation(), id.idRange)) @@ -11262,7 +11266,7 @@ and AnalyzeRecursiveInstanceMemberDecl let argsAndRetTy = NewInferenceType g UnifyTypes cenv envinner mBinding ty (mkFunTy g thisTy argsAndRetTy) - CheckForNonAbstractInterface declKind tcref memberFlags memberId.idRange + CheckForNonAbstractInterface g declKind tcref memberFlags false memberId.idRange // Determine if a uniquely-identified-override exists based on the information // at the member signature. If so, we know the type of this member, and the full slotsig diff --git a/src/Compiler/Checking/CheckExpressions.fsi b/src/Compiler/Checking/CheckExpressions.fsi index 5c2b0b6451f..0e079eeec33 100644 --- a/src/Compiler/Checking/CheckExpressions.fsi +++ b/src/Compiler/Checking/CheckExpressions.fsi @@ -389,7 +389,13 @@ val AnalyzeAndMakeAndPublishRecursiveValue: /// Check that a member can be included in an interface val CheckForNonAbstractInterface: - declKind: DeclKind -> tcref: TyconRef -> memberFlags: SynMemberFlags -> m: range -> unit + g: TcGlobals -> + declKind: DeclKind -> + tcref: TyconRef -> + memberFlags: SynMemberFlags -> + isMemberStatic: bool -> + m: range -> + unit /// Check the flags on a member definition for consistency val CheckMemberFlags: diff --git a/src/Compiler/Checking/CheckIncrementalClasses.fs b/src/Compiler/Checking/CheckIncrementalClasses.fs index fe7e1a2393c..7ace6fe83b3 100644 --- a/src/Compiler/Checking/CheckIncrementalClasses.fs +++ b/src/Compiler/Checking/CheckIncrementalClasses.fs @@ -128,7 +128,7 @@ let TcImplicitCtorLhs_Phase2A(cenv: cenv, env, tpenv, tcref: TyconRef, vis, attr let valSynData = SynValInfo([synArgInfos], SynInfo.unnamedRetVal) let id = ident ("new", m) - CheckForNonAbstractInterface ModuleOrMemberBinding tcref memberFlags id.idRange + CheckForNonAbstractInterface g ModuleOrMemberBinding tcref memberFlags false id.idRange let memberInfo = MakeMemberDataAndMangledNameForMemberVal(g, tcref, false, attribs, [], memberFlags, valSynData, id, false) let prelimValReprInfo = TranslateSynValInfo m (TcAttributes cenv env) valSynData let prelimTyschemeG = GeneralizedType(copyOfTyconTypars, ctorTy) @@ -152,7 +152,7 @@ let TcImplicitCtorLhs_Phase2A(cenv: cenv, env, tpenv, tcref: TyconRef, vis, attr let cctorTy = mkFunTy g g.unit_ty g.unit_ty let valSynData = SynValInfo([[]], SynInfo.unnamedRetVal) let id = ident ("cctor", m) - CheckForNonAbstractInterface ModuleOrMemberBinding tcref ClassCtorMemberFlags id.idRange + CheckForNonAbstractInterface g ModuleOrMemberBinding tcref ClassCtorMemberFlags false id.idRange let memberInfo = MakeMemberDataAndMangledNameForMemberVal(g, tcref, false, [], [], ClassCtorMemberFlags, valSynData, id, false) let prelimValReprInfo = TranslateSynValInfo m (TcAttributes cenv env) valSynData let prelimTyschemeG = GeneralizedType(copyOfTyconTypars, cctorTy) diff --git a/src/Compiler/Checking/infos.fs b/src/Compiler/Checking/infos.fs index 68e844fa919..a012d9260e3 100644 --- a/src/Compiler/Checking/infos.fs +++ b/src/Compiler/Checking/infos.fs @@ -866,9 +866,7 @@ type MethInfo = member x.IsDispatchSlot = match x with | ILMeth(_g, ilmeth, _) -> ilmeth.IsVirtual - | FSMeth(g, _, vref, _) as x -> - isInterfaceTy g x.ApparentEnclosingType || - vref.MemberInfo.Value.MemberFlags.IsDispatchSlot + | FSMeth(_, _, vref, _) -> vref.MemberInfo.Value.MemberFlags.IsDispatchSlot | DefaultStructCtor _ -> false #if !NO_TYPEPROVIDERS | ProvidedMeth _ -> x.IsVirtual // Note: follow same implementation as ILMeth diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index 063a6b973c8..b13769ab5ce 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -717,7 +717,7 @@ tcUnnamedArgumentsDoNotFormPrefix,"The unnamed arguments do not form a prefix of 865,tcStaticInitializersIllegalInInterface,"Interfaces cannot contain definitions of static initializers" 866,tcObjectConstructorsIllegalInInterface,"Interfaces cannot contain definitions of object constructors" 867,tcMemberOverridesIllegalInInterface,"Interfaces cannot contain definitions of member overrides" -868,tcConcreteMembersIllegalInInterface,"Interfaces cannot contain definitions of concrete members. You may need to define a constructor on your type to indicate that the type is a class." +868,tcConcreteMembersIllegalInInterface,"Interfaces cannot contain definitions of concrete instance members. You may need to define a constructor on your type to indicate that the type is a class." 869,tcConstructorsDisallowedInExceptionAugmentation,"Constructors cannot be specified in exception augmentations" 870,tcStructsCannotHaveConstructorWithNoArguments,"Structs cannot have an object constructor with no arguments. This is a restriction imposed on all CLI languages as structs automatically support a default constructor." 871,tcConstructorsIllegalForThisType,"Constructors cannot be defined for this type" @@ -1563,6 +1563,7 @@ featureArithmeticInLiterals,"Allow arithmetic and logical operations in literals featureErrorReportingOnStaticClasses,"Error reporting on static classes" featureTryWithInSeqExpressions,"Support for try-with in sequence expressions" featureWarningWhenCopyAndUpdateRecordChangesAllFields,"Raises warnings when an copy-and-update record expression changes all fields of a record." +featureStaticMembersInInterfaces,"Static members in interfaces" 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." diff --git a/src/Compiler/Facilities/LanguageFeatures.fs b/src/Compiler/Facilities/LanguageFeatures.fs index 46748d6f889..095e12ac95a 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fs +++ b/src/Compiler/Facilities/LanguageFeatures.fs @@ -63,6 +63,7 @@ type LanguageFeature = | ErrorReportingOnStaticClasses | TryWithInSeqExpression | WarningWhenCopyAndUpdateRecordChangesAllFields + | StaticMembersInInterfaces /// LanguageVersion management type LanguageVersion(versionText) = @@ -142,6 +143,7 @@ type LanguageVersion(versionText) = LanguageFeature.ErrorReportingOnStaticClasses, previewVersion LanguageFeature.TryWithInSeqExpression, previewVersion LanguageFeature.WarningWhenCopyAndUpdateRecordChangesAllFields, previewVersion + LanguageFeature.StaticMembersInInterfaces, previewVersion ] @@ -258,6 +260,7 @@ type LanguageVersion(versionText) = | LanguageFeature.ErrorReportingOnStaticClasses -> FSComp.SR.featureErrorReportingOnStaticClasses () | LanguageFeature.TryWithInSeqExpression -> FSComp.SR.featureTryWithInSeqExpressions () | LanguageFeature.WarningWhenCopyAndUpdateRecordChangesAllFields -> FSComp.SR.featureWarningWhenCopyAndUpdateRecordChangesAllFields () + | LanguageFeature.StaticMembersInInterfaces -> FSComp.SR.featureStaticMembersInInterfaces () /// Get a version string associated with the given feature. static member GetFeatureVersionString feature = diff --git a/src/Compiler/Facilities/LanguageFeatures.fsi b/src/Compiler/Facilities/LanguageFeatures.fsi index 8ab8b72704b..badfce8c012 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fsi +++ b/src/Compiler/Facilities/LanguageFeatures.fsi @@ -53,6 +53,7 @@ type LanguageFeature = | ErrorReportingOnStaticClasses | TryWithInSeqExpression | WarningWhenCopyAndUpdateRecordChangesAllFields + | StaticMembersInInterfaces /// LanguageVersion management type LanguageVersion = diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index b6ad7c62f3a..c81fe4e8f56 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -372,6 +372,11 @@ vzor s jedním podtržítkem + + Static members in interfaces + Static members in interfaces + + string interpolation interpolace řetězce @@ -382,19 +387,16 @@ reprezentace struktury aktivních vzorů - Support for try-with in sequence expressions Support for try-with in sequence expressions - Raises warnings when an copy-and-update record expression changes all fields of a record. Raises warnings when an copy-and-update record expression changes all fields of a record. - Raises warnings when 'let inline ... =' is used together with [<MethodImpl(MethodImplOptions.NoInlining)>] attribute. Function is not getting inlined. Vyvolá upozornění, když se použije „let inline ... =“ společně s atributem [<MethodImpl(MethodImplOptions.NoInlining)>]. Funkce není vkládána. @@ -4626,8 +4628,8 @@ - Interfaces cannot contain definitions of concrete members. You may need to define a constructor on your type to indicate that the type is a class. - Rozhraní nemůžou obsahovat definice konkrétních členů. Možná bude potřeba definovat u typu konstruktor, který bude vyjadřovat, že jde o třídu. + Interfaces cannot contain definitions of concrete instance members. You may need to define a constructor on your type to indicate that the type is a class. + Rozhraní nemůžou obsahovat definice konkrétních členů. Možná bude potřeba definovat u typu konstruktor, který bude vyjadřovat, že jde o třídu. diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index 52f3d52cf26..fffff96ecc3 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -372,6 +372,11 @@ Muster mit einzelnem Unterstrich + + Static members in interfaces + Static members in interfaces + + string interpolation Zeichenfolgeninterpolation @@ -382,19 +387,16 @@ Strukturdarstellung für aktive Muster - Support for try-with in sequence expressions Support for try-with in sequence expressions - Raises warnings when an copy-and-update record expression changes all fields of a record. Raises warnings when an copy-and-update record expression changes all fields of a record. - Raises warnings when 'let inline ... =' is used together with [<MethodImpl(MethodImplOptions.NoInlining)>] attribute. Function is not getting inlined. Löst Warnungen aus, wenn „let inline ... =“ zusammen mit dem Attribut [<MethodImpl(MethodImplOptions.NoInlining)>] verwendet wird. Die Funktion wird nicht inline gesetzt. @@ -4626,8 +4628,8 @@ - Interfaces cannot contain definitions of concrete members. You may need to define a constructor on your type to indicate that the type is a class. - Schnittstellen dürfen keine Definitionen konkreter Member enthalten. Sie müssen ggf. einen Konstruktor für den Typ definieren, um anzugeben, dass es sich bei dem Typ um eine Klasse handelt. + Interfaces cannot contain definitions of concrete instance members. You may need to define a constructor on your type to indicate that the type is a class. + Schnittstellen dürfen keine Definitionen konkreter Member enthalten. Sie müssen ggf. einen Konstruktor für den Typ definieren, um anzugeben, dass es sich bei dem Typ um eine Klasse handelt. diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index 298deb31137..7a7c32069e7 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -372,6 +372,11 @@ patrón de subrayado simple + + Static members in interfaces + Static members in interfaces + + string interpolation interpolación de cadena @@ -382,19 +387,16 @@ representación de struct para modelos activos - Support for try-with in sequence expressions Support for try-with in sequence expressions - Raises warnings when an copy-and-update record expression changes all fields of a record. Raises warnings when an copy-and-update record expression changes all fields of a record. - Raises warnings when 'let inline ... =' is used together with [<MethodImpl(MethodImplOptions.NoInlining)>] attribute. Function is not getting inlined. Genera advertencias cuando se usa "let inline ... =" junto con el atributo [<MethodImpl(MethodImplOptions.NoInlining)>]. La función no se está insertando. @@ -4626,8 +4628,8 @@ - Interfaces cannot contain definitions of concrete members. You may need to define a constructor on your type to indicate that the type is a class. - Las interfaces no pueden contener definiciones de miembros concretos. Puede ser necesario definir un constructor en el tipo para indicar que el tipo es una clase. + Interfaces cannot contain definitions of concrete instance members. You may need to define a constructor on your type to indicate that the type is a class. + Las interfaces no pueden contener definiciones de miembros concretos. Puede ser necesario definir un constructor en el tipo para indicar que el tipo es una clase. diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index d41d7f05761..bfe8bff317b 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -372,6 +372,11 @@ modèle de trait de soulignement unique + + Static members in interfaces + Static members in interfaces + + string interpolation interpolation de chaîne @@ -382,19 +387,16 @@ représentation de structure pour les modèles actifs - Support for try-with in sequence expressions Support for try-with in sequence expressions - Raises warnings when an copy-and-update record expression changes all fields of a record. Raises warnings when an copy-and-update record expression changes all fields of a record. - Raises warnings when 'let inline ... =' is used together with [<MethodImpl(MethodImplOptions.NoInlining)>] attribute. Function is not getting inlined. Génère des avertissements lorsque « let inline ... = » est utilisé avec l’attribut [<MethodImpl(MethodImplOptions.NoInlining)>]. La fonction n’est pas inlined. @@ -4626,8 +4628,8 @@ - Interfaces cannot contain definitions of concrete members. You may need to define a constructor on your type to indicate that the type is a class. - Les interfaces ne peuvent pas contenir de définitions de membres concrets. Vous pouvez définir un constructeur sur votre type pour indiquer que le type est une classe. + Interfaces cannot contain definitions of concrete instance members. You may need to define a constructor on your type to indicate that the type is a class. + Les interfaces ne peuvent pas contenir de définitions de membres concrets. Vous pouvez définir un constructeur sur votre type pour indiquer que le type est une classe. diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index 083f98e4dfa..e6419dfc465 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -372,6 +372,11 @@ criterio per carattere di sottolineatura singolo + + Static members in interfaces + Static members in interfaces + + string interpolation interpolazione di stringhe @@ -382,19 +387,16 @@ rappresentazione struct per criteri attivi - Support for try-with in sequence expressions Support for try-with in sequence expressions - Raises warnings when an copy-and-update record expression changes all fields of a record. Raises warnings when an copy-and-update record expression changes all fields of a record. - Raises warnings when 'let inline ... =' is used together with [<MethodImpl(MethodImplOptions.NoInlining)>] attribute. Function is not getting inlined. Genera avvisi quando 'let inline ... =' viene usato insieme all'attributo [<MethodImpl(MethodImplOptions.NoInlining)>]. La funzione non viene resa inline. @@ -4626,8 +4628,8 @@ - Interfaces cannot contain definitions of concrete members. You may need to define a constructor on your type to indicate that the type is a class. - Le interfacce non possono contenere definizioni di membri concreti. Potrebbe essere necessario definire un costruttore nel tipo utilizzato per indicare che il tipo è una classe. + Interfaces cannot contain definitions of concrete instance members. You may need to define a constructor on your type to indicate that the type is a class. + Le interfacce non possono contenere definizioni di membri concreti. Potrebbe essere necessario definire un costruttore nel tipo utilizzato per indicare che il tipo è una classe. diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index 85735c3b4e2..b565ccf6694 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -372,6 +372,11 @@ 単一のアンダースコア パターン + + Static members in interfaces + Static members in interfaces + + string interpolation 文字列の補間 @@ -382,19 +387,16 @@ アクティブなパターンの構造体表現 - Support for try-with in sequence expressions Support for try-with in sequence expressions - Raises warnings when an copy-and-update record expression changes all fields of a record. Raises warnings when an copy-and-update record expression changes all fields of a record. - Raises warnings when 'let inline ... =' is used together with [<MethodImpl(MethodImplOptions.NoInlining)>] attribute. Function is not getting inlined. 'let inline ... =' が [<MethodImpl(MethodImplOptions.NoInlining)>] 属性と一緒に使用されるときに警告を生成します。関数はインライン化されていません。 @@ -4626,8 +4628,8 @@ - Interfaces cannot contain definitions of concrete members. You may need to define a constructor on your type to indicate that the type is a class. - インターフェイスに具象メンバーの定義を含めることはできません。必要に応じて、型にコンストラクターを定義して、型がクラスであることを示してください。 + Interfaces cannot contain definitions of concrete instance members. You may need to define a constructor on your type to indicate that the type is a class. + インターフェイスに具象メンバーの定義を含めることはできません。必要に応じて、型にコンストラクターを定義して、型がクラスであることを示してください。 diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index 2b32dd65949..c75c9cf1435 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -372,6 +372,11 @@ 단일 밑줄 패턴 + + Static members in interfaces + Static members in interfaces + + string interpolation 문자열 보간 @@ -382,19 +387,16 @@ 활성 패턴에 대한 구조체 표현 - Support for try-with in sequence expressions Support for try-with in sequence expressions - Raises warnings when an copy-and-update record expression changes all fields of a record. Raises warnings when an copy-and-update record expression changes all fields of a record. - Raises warnings when 'let inline ... =' is used together with [<MethodImpl(MethodImplOptions.NoInlining)>] attribute. Function is not getting inlined. 'let inline ... ='을(를) [<MethodImpl(MethodImplOptions.NoInlining)>] 특성과 함께 사용하는 경우 경고를 발생합니다. 함수가 인라인되지 않습니다. @@ -4626,8 +4628,8 @@ - Interfaces cannot contain definitions of concrete members. You may need to define a constructor on your type to indicate that the type is a class. - 인터페이스에는 구체적인 멤버의 정의를 포함할 수 없습니다. 사용자 형식에 대한 생성자를 정의하여 해당 형식이 클래스임을 나타내야 할 수 있습니다. + Interfaces cannot contain definitions of concrete instance members. You may need to define a constructor on your type to indicate that the type is a class. + 인터페이스에는 구체적인 멤버의 정의를 포함할 수 없습니다. 사용자 형식에 대한 생성자를 정의하여 해당 형식이 클래스임을 나타내야 할 수 있습니다. diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index ee6b6afe9ac..6cf95f5eaa4 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -372,6 +372,11 @@ wzorzec z pojedynczym podkreśleniem + + Static members in interfaces + Static members in interfaces + + string interpolation interpolacja ciągu @@ -382,19 +387,16 @@ reprezentacja struktury aktywnych wzorców - Support for try-with in sequence expressions Support for try-with in sequence expressions - Raises warnings when an copy-and-update record expression changes all fields of a record. Raises warnings when an copy-and-update record expression changes all fields of a record. - Raises warnings when 'let inline ... =' is used together with [<MethodImpl(MethodImplOptions.NoInlining)>] attribute. Function is not getting inlined. Zgłasza ostrzeżenia, gdy element „let inline ... =” jest używany razem z atrybutem [<MethodImpl(MethodImplOptions.NoInlining)>]. Funkcja nie jest wstawiana. @@ -4626,8 +4628,8 @@ - Interfaces cannot contain definitions of concrete members. You may need to define a constructor on your type to indicate that the type is a class. - Interfejsy nie mogą zawierać definicji konkretnych elementów członkowskich. Może być konieczne zdefiniowanie konstruktora w typie, aby określić, że typ to klasa. + Interfaces cannot contain definitions of concrete instance members. You may need to define a constructor on your type to indicate that the type is a class. + Interfejsy nie mogą zawierać definicji konkretnych elementów członkowskich. Może być konieczne zdefiniowanie konstruktora w typie, aby określić, że typ to klasa. diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index 8ad44f41ea6..56eb6903278 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -372,6 +372,11 @@ padrão de sublinhado simples + + Static members in interfaces + Static members in interfaces + + string interpolation interpolação da cadeia de caracteres @@ -382,19 +387,16 @@ representação estrutural para padrões ativos - Support for try-with in sequence expressions Support for try-with in sequence expressions - Raises warnings when an copy-and-update record expression changes all fields of a record. Raises warnings when an copy-and-update record expression changes all fields of a record. - Raises warnings when 'let inline ... =' is used together with [<MethodImpl(MethodImplOptions.NoInlining)>] attribute. Function is not getting inlined. Gera avisos quando 'let inline ... =' é usado junto com o atributo [<MethodImpl(MethodImplOptions.NoInlining)>]. A função não está sendo embutida. @@ -4626,8 +4628,8 @@ - Interfaces cannot contain definitions of concrete members. You may need to define a constructor on your type to indicate that the type is a class. - Interfaces não podem conter definições de membros concretos. Talvez seja necessário definir um construtor no seu tipo para indicar que o tipo é uma classe. + Interfaces cannot contain definitions of concrete instance members. You may need to define a constructor on your type to indicate that the type is a class. + Interfaces não podem conter definições de membros concretos. Talvez seja necessário definir um construtor no seu tipo para indicar que o tipo é uma classe. diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index 0cbd637dd4d..81a41024002 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -372,6 +372,11 @@ шаблон с одним подчеркиванием + + Static members in interfaces + Static members in interfaces + + string interpolation интерполяция строк @@ -382,19 +387,16 @@ представление структуры для активных шаблонов - Support for try-with in sequence expressions Support for try-with in sequence expressions - Raises warnings when an copy-and-update record expression changes all fields of a record. Raises warnings when an copy-and-update record expression changes all fields of a record. - Raises warnings when 'let inline ... =' is used together with [<MethodImpl(MethodImplOptions.NoInlining)>] attribute. Function is not getting inlined. Выдает предупреждения, когда используется параметр "let inline ... =" вместе с атрибутом [<MethodImpl(MethodImplOptions.NoInlining)>]. Функция не встраивается. @@ -4626,8 +4628,8 @@ - Interfaces cannot contain definitions of concrete members. You may need to define a constructor on your type to indicate that the type is a class. - Интерфейсы не могут содержать определений конкретных элементов. Чтобы указать, что тип является классом, возможно, потребуется определить конструктор для типа. + Interfaces cannot contain definitions of concrete instance members. You may need to define a constructor on your type to indicate that the type is a class. + Интерфейсы не могут содержать определений конкретных элементов. Чтобы указать, что тип является классом, возможно, потребуется определить конструктор для типа. diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index c9713648da3..8b6882ff1b4 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -372,6 +372,11 @@ tek alt çizgi deseni + + Static members in interfaces + Static members in interfaces + + string interpolation dizede düz metin arasına kod ekleme @@ -382,19 +387,16 @@ etkin desenler için yapı gösterimi - Support for try-with in sequence expressions Support for try-with in sequence expressions - Raises warnings when an copy-and-update record expression changes all fields of a record. Raises warnings when an copy-and-update record expression changes all fields of a record. - Raises warnings when 'let inline ... =' is used together with [<MethodImpl(MethodImplOptions.NoInlining)>] attribute. Function is not getting inlined. [<MethodImpl(MethodImplOptions.NoInlining)>] özniteliği ile birlikte 'let inline ... =' kullanıldığında uyarı verir. İşlev satır içine alınmıyor. @@ -4626,8 +4628,8 @@ - Interfaces cannot contain definitions of concrete members. You may need to define a constructor on your type to indicate that the type is a class. - Arabirimler somut üyelerin tanımlarını içeremez. Türün sınıf olduğunu belirtmek için türünüzde bir oluşturucu tanımlamanız gerekebilir. + Interfaces cannot contain definitions of concrete instance members. You may need to define a constructor on your type to indicate that the type is a class. + Arabirimler somut üyelerin tanımlarını içeremez. Türün sınıf olduğunu belirtmek için türünüzde bir oluşturucu tanımlamanız gerekebilir. diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index 4072aaad792..f39f82d2045 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -372,6 +372,11 @@ 单下划线模式 + + Static members in interfaces + Static members in interfaces + + string interpolation 字符串内插 @@ -382,19 +387,16 @@ 活动模式的结构表示形式 - Support for try-with in sequence expressions Support for try-with in sequence expressions - Raises warnings when an copy-and-update record expression changes all fields of a record. Raises warnings when an copy-and-update record expression changes all fields of a record. - Raises warnings when 'let inline ... =' is used together with [<MethodImpl(MethodImplOptions.NoInlining)>] attribute. Function is not getting inlined. 当 "let inline ... =" 与 [<MethodImpl(MethodImplOptions.NoInlining)>] 属性一起使用时引发警告。函数未内联。 @@ -4626,8 +4628,8 @@ - Interfaces cannot contain definitions of concrete members. You may need to define a constructor on your type to indicate that the type is a class. - 接口不能包含具体成员的定义。您可能需要定义类型的构造函数来指示该类型是类。 + Interfaces cannot contain definitions of concrete instance members. You may need to define a constructor on your type to indicate that the type is a class. + 接口不能包含具体成员的定义。您可能需要定义类型的构造函数来指示该类型是类。 diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index bd871bbba49..1529a87f1cb 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -372,6 +372,11 @@ 單一底線模式 + + Static members in interfaces + Static members in interfaces + + string interpolation 字串內插補點 @@ -382,19 +387,16 @@ 現用模式的結構表示法 - Support for try-with in sequence expressions Support for try-with in sequence expressions - Raises warnings when an copy-and-update record expression changes all fields of a record. Raises warnings when an copy-and-update record expression changes all fields of a record. - Raises warnings when 'let inline ... =' is used together with [<MethodImpl(MethodImplOptions.NoInlining)>] attribute. Function is not getting inlined. 當 'let inline ... =' 與 [<MethodImpl(MethodImplOptions.NoInlining)>] 屬性一起使用時引發警告。函數未內嵌。 @@ -4626,8 +4628,8 @@ - Interfaces cannot contain definitions of concrete members. You may need to define a constructor on your type to indicate that the type is a class. - 介面不能包含具象成員的定義。您必須在類型上定義建構函式,以指示類型是類別。 + Interfaces cannot contain definitions of concrete instance members. You may need to define a constructor on your type to indicate that the type is a class. + 介面不能包含具象成員的定義。您必須在類型上定義建構函式,以指示類型是類別。 diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index 237aad841d5..00d8ebd1136 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -181,6 +181,7 @@ + diff --git a/tests/FSharp.Compiler.ComponentTests/Language/InterfaceTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/InterfaceTests.fs new file mode 100644 index 00000000000..97a0798e1da --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Language/InterfaceTests.fs @@ -0,0 +1,85 @@ +module FSharp.Compiler.ComponentTests.Language.InterfaceTests + +open Xunit +open FSharp.Test.Compiler + +[] +let ``Concrete instance method is not allowed in interfaces in lang preview``() = + FSharp $""" +[] +type I = + member _.X () = 1 + """ + |> withLangVersionPreview + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 868, Line 4, Col 14, Line 4, Col 15, "Interfaces cannot contain definitions of concrete instance members. You may need to define a constructor on your type to indicate that the type is a class.") + ] + +[] +let ``Concrete instance property is not allowed in interfaces in lang preview``() = + FSharp $""" +[] +type I = + member _.Prop = "x" + """ + |> withLangVersionPreview + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 868, Line 4, Col 14, Line 4, Col 18, "Interfaces cannot contain definitions of concrete instance members. You may need to define a constructor on your type to indicate that the type is a class.") + ] + +[] +let ``Concrete static members are allowed in interfaces in lang preview``() = + FSharp $""" +[] +type I<'T> = + static member Echo (x: 'T) = x + static member Prop = Unchecked.defaultof<'T> + +if I.Echo 42 <> 42 || I.Prop <> 0 || not (isNull I.Prop) then + failwith "failed" + """ + |> withLangVersionPreview + |> asExe + |> compileAndRun + |> shouldSucceed + +[] +let ``Concrete static members are not allowed in interfaces in lang version70``() = + FSharp $""" +[] +type I<'T> = + static member Echo (x: 'T) = x + static member Prop = Unchecked.defaultof<'T> + """ + |> withLangVersion70 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 3350, Line 4, Col 19, Line 4, Col 23, "Feature 'Static members in interfaces' is not available in F# 7.0. Please use language version 'PREVIEW' or greater.") + ] + +[] +let ``Interface with concrete static members can be implemented in lang preview``() = + FSharp $""" +[] +type I = + static member Echo (x: string) = x + abstract member Blah: int + +type Imp () = + interface I with + member _.Blah = 3 + +let o = {{ new I with member _.Blah = 4 }} + +if I.Echo "yup" <> "yup" || (Imp() :> I).Blah <> 3 || o.Blah <> 4 then + failwith "failed" + """ + |> withLangVersionPreview + |> asExe + |> compileAndRun + |> shouldSucceed \ No newline at end of file