未验证 提交 c8acf2ac 编写于 作者: R Ross Kuehl 提交者: GitHub

Use logical operator name to check for logical ternary operator (#14495)

上级 85543b5b
...@@ -1015,15 +1015,16 @@ let MakeMemberDataAndMangledNameForMemberVal(g, tcref, isExtrinsic, attrs, implS ...@@ -1015,15 +1015,16 @@ let MakeMemberDataAndMangledNameForMemberVal(g, tcref, isExtrinsic, attrs, implS
if not isCompGen && IsLogicalInfixOpName id.idText then if not isCompGen && IsLogicalInfixOpName id.idText then
let m = id.idRange let m = id.idRange
let name = ConvertValLogicalNameToDisplayNameCore id.idText let logicalName = id.idText
let displayName = ConvertValLogicalNameToDisplayNameCore logicalName
// Check symbolic members. Expect valSynData implied arity to be [[2]]. // Check symbolic members. Expect valSynData implied arity to be [[2]].
match SynInfo.AritiesOfArgs valSynData with match SynInfo.AritiesOfArgs valSynData with
| [] | [0] -> warning(Error(FSComp.SR.memberOperatorDefinitionWithNoArguments name, m)) | [] | [0] -> warning(Error(FSComp.SR.memberOperatorDefinitionWithNoArguments displayName, m))
| n :: otherArgs -> | n :: otherArgs ->
let opTakesThreeArgs = IsLogicalTernaryOperator name let opTakesThreeArgs = IsLogicalTernaryOperator logicalName
if n<>2 && not opTakesThreeArgs then warning(Error(FSComp.SR.memberOperatorDefinitionWithNonPairArgument(name, n), m)) if n<>2 && not opTakesThreeArgs then warning(Error(FSComp.SR.memberOperatorDefinitionWithNonPairArgument(displayName, n), m))
if n<>3 && opTakesThreeArgs then warning(Error(FSComp.SR.memberOperatorDefinitionWithNonTripleArgument(name, n), m)) if n<>3 && opTakesThreeArgs then warning(Error(FSComp.SR.memberOperatorDefinitionWithNonTripleArgument(displayName, n), m))
if not (isNil otherArgs) then warning(Error(FSComp.SR.memberOperatorDefinitionWithCurriedArguments name, m)) if not (isNil otherArgs) then warning(Error(FSComp.SR.memberOperatorDefinitionWithCurriedArguments displayName, m))
if isExtrinsic && IsLogicalOpName id.idText then if isExtrinsic && IsLogicalOpName id.idText then
warning(Error(FSComp.SR.tcMemberOperatorDefinitionInExtrinsic(), id.idRange)) warning(Error(FSComp.SR.tcMemberOperatorDefinitionInExtrinsic(), id.idRange))
......
...@@ -173,6 +173,7 @@ ...@@ -173,6 +173,7 @@
<Compile Include="Language\CodeQuotationTests.fs" /> <Compile Include="Language\CodeQuotationTests.fs" />
<Compile Include="Language\InterpolatedStringsTests.fs" /> <Compile Include="Language\InterpolatedStringsTests.fs" />
<Compile Include="Language\ComputationExpressionTests.fs" /> <Compile Include="Language\ComputationExpressionTests.fs" />
<Compile Include="Language\DynamicAssignmentOperatorTests.fs" />
<Compile Include="Language\CastingTests.fs" /> <Compile Include="Language\CastingTests.fs" />
<Compile Include="Language\NameofTests.fs" /> <Compile Include="Language\NameofTests.fs" />
<Compile Include="Language\ExtensionMethodTests.fs" /> <Compile Include="Language\ExtensionMethodTests.fs" />
......
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
namespace FSharp.Compiler.ComponentTests.Language
open System
open Xunit
open FSharp.Test.Compiler
module DynamicAssignmentOperatorTests =
[<Theory>]
[<InlineData("6.0")>]
[<InlineData("7.0")>]
let ``Implementing dynamic assignment operator does not produce a warning`` version =
Fsx """
type T = T with
static member inline (?<-) (f, x, y) = f x y
"""
|> withLangVersion version
|> compile
|> shouldSucceed
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册