diff --git a/src/fsharp/AccessibilityLogic.fs b/src/fsharp/AccessibilityLogic.fs index 05325646d11..3d5aadc98cc 100644 --- a/src/fsharp/AccessibilityLogic.fs +++ b/src/fsharp/AccessibilityLogic.fs @@ -249,12 +249,53 @@ let private IsILMethInfoAccessible g amap m adType ad ilminfo = let GetILAccessOfILPropInfo (ILPropInfo(tinfo, pdef)) = let tdef = tinfo.RawMetadata let ilAccess = - match pdef.GetMethod with - | Some mref -> (resolveILMethodRef tdef mref).Access - | None -> - match pdef.SetMethod with - | None -> ILMemberAccess.Public - | Some mref -> (resolveILMethodRef tdef mref).Access + match pdef.GetMethod, pdef.SetMethod with + | Some mref, None + | None, Some mref -> (resolveILMethodRef tdef mref).Access + + | Some mrefGet, Some mrefSet -> + // + // Dotnet properties have a getter and a setter method, each of which can have a separate visibility public, protected, private etc ... + // This code computes the visibility for the property by choosing the most visible method. This approximation is usefull for cases + // where the compiler needs to know the visibility of the property. + // The specific ordering for choosing the most visible is: + // ILMemberAccess.Public, + // ILMemberAccess.FamilyOrAssembly + // ILMemberAccess.Assembly + // ILMemberAccess.Family + // ILMemberAccess.FamilyAndAssembly + // ILMemberAccess.Private + // ILMemberAccess.CompilerControlled + // + let getA = (resolveILMethodRef tdef mrefGet).Access + let setA = (resolveILMethodRef tdef mrefSet).Access + + // Use the accessors to determine the visibility of the property. + // N.B. It is critical to keep the ordering in decreasing visibility order in the following match expression + match getA, setA with + | ILMemberAccess.Public, _ + | _, ILMemberAccess.Public -> ILMemberAccess.Public + + | ILMemberAccess.FamilyOrAssembly, _ + | _, ILMemberAccess.FamilyOrAssembly -> ILMemberAccess.FamilyOrAssembly + + | ILMemberAccess.Assembly, _ + | _, ILMemberAccess.Assembly -> ILMemberAccess.Assembly + + | ILMemberAccess.Family, _ + | _, ILMemberAccess.Family -> ILMemberAccess.Family + + | ILMemberAccess.FamilyAndAssembly, _ + | _, ILMemberAccess.FamilyAndAssembly -> ILMemberAccess.FamilyAndAssembly + + | ILMemberAccess.Private, _ + | _, ILMemberAccess.Private -> ILMemberAccess.Private + + | ILMemberAccess.CompilerControlled, _ + | _, ILMemberAccess.CompilerControlled -> ILMemberAccess.CompilerControlled + + | None, None -> ILMemberAccess.Public + ilAccess let IsILPropInfoAccessible g amap m ad pinfo = @@ -323,8 +364,11 @@ let IsMethInfoAccessible amap m ad minfo = IsTypeAndMethInfoAccessible amap m ad let IsPropInfoAccessible g amap m ad = function | ILProp ilpinfo -> IsILPropInfoAccessible g amap m ad ilpinfo - | FSProp (_, _, Some vref, _) - | FSProp (_, _, _, Some vref) -> IsValAccessible ad vref + | FSProp (_, _, Some vref, None) + | FSProp (_, _, None, Some vref) -> IsValAccessible ad vref + | FSProp (_, _, Some vrefGet, Some vrefSet) -> + // pick most accessible + IsValAccessible ad vrefGet || IsValAccessible ad vrefSet #if !NO_EXTENSIONTYPING | ProvidedProp (amap, tppi, m) as pp-> let access = @@ -343,4 +387,3 @@ let IsPropInfoAccessible g amap m ad = function let IsFieldInfoAccessible ad (rfref:RecdFieldInfo) = IsAccessible ad rfref.RecdField.Accessibility - diff --git a/src/fsharp/FSComp.txt b/src/fsharp/FSComp.txt index 6dcf26f7c22..e8d7455b508 100644 --- a/src/fsharp/FSComp.txt +++ b/src/fsharp/FSComp.txt @@ -1512,4 +1512,4 @@ featureFixedIndexSlice3d4d,"fixed-index slice 3d/4d" featureAndBang,"applicative computation expressions" featureNullableOptionalInterop,"nullable optional interop" featureDefaultInterfaceMemberConsumption,"default interface member consumption" -featureWitnessPassing,"witness passing" +featureWitnessPassing,"witness passing for trait constraints in F# quotations" diff --git a/src/fsharp/FSharp.Core/string.fs b/src/fsharp/FSharp.Core/string.fs index 7e4b65f1a08..d009615e6aa 100644 --- a/src/fsharp/FSharp.Core/string.fs +++ b/src/fsharp/FSharp.Core/string.fs @@ -12,6 +12,11 @@ namespace Microsoft.FSharp.Core [] [] module String = + [] + /// LOH threshold is calculated from FSharp.Compiler.AbstractIL.Internal.Library.LOH_SIZE_THRESHOLD_BYTES, + /// and is equal to 80_000 / sizeof + let LOH_CHAR_THRESHOLD = 40_000 + [] let length (str:string) = if isNull str then 0 else str.Length @@ -37,9 +42,13 @@ namespace Microsoft.FSharp.Core if String.IsNullOrEmpty str then String.Empty else - let res = StringBuilder str.Length - str |> iter (fun c -> res.Append(mapping c) |> ignore) - res.ToString() + let result = str.ToCharArray() + let mutable i = 0 + for c in result do + result.[i] <- mapping c + i <- i + 1 + + new String(result) [] let mapi (mapping: int -> char -> char) (str:string) = @@ -53,13 +62,30 @@ namespace Microsoft.FSharp.Core [] let filter (predicate: char -> bool) (str:string) = - if String.IsNullOrEmpty str then + let len = length str + + if len = 0 then String.Empty - else - let res = StringBuilder str.Length + + elif len > LOH_CHAR_THRESHOLD then + // By using SB here, which is twice slower than the optimized path, we prevent LOH allocations + // and 'stop the world' collections if the filtering results in smaller strings. + // We also don't pre-allocate SB here, to allow for less mem pressure when filter result is small. + let res = StringBuilder() str |> iter (fun c -> if predicate c then res.Append c |> ignore) res.ToString() + else + // Must do it this way, since array.fs is not yet in scope, but this is safe + let target = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked len + let mutable i = 0 + for c in str do + if predicate c then + target.[i] <- c + i <- i + 1 + + String(target, 0, i) + [] let collect (mapping: char -> string) (str:string) = if String.IsNullOrEmpty str then @@ -81,13 +107,38 @@ namespace Microsoft.FSharp.Core let replicate (count:int) (str:string) = if count < 0 then invalidArgInputMustBeNonNegative "count" count - if String.IsNullOrEmpty str then + let len = length str + if len = 0 || count = 0 then String.Empty + + elif len = 1 then + new String(str.[0], count) + + elif count <= 4 then + match count with + | 1 -> str + | 2 -> String.Concat(str, str) + | 3 -> String.Concat(str, str, str) + | _ -> String.Concat(str, str, str, str) + else - let res = StringBuilder(count * str.Length) - for i = 0 to count - 1 do - res.Append str |> ignore - res.ToString() + // Using the primitive, because array.fs is not yet in scope. It's safe: both len and count are positive. + let target = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked (len * count) + let source = str.ToCharArray() + + // O(log(n)) performance loop: + // Copy first string, then keep copying what we already copied + // (i.e., doubling it) until we reach or pass the halfway point + Array.Copy(source, 0, target, 0, len) + let mutable i = len + while i * 2 < target.Length do + Array.Copy(target, 0, target, i, i) + i <- i * 2 + + // finally, copy the remain half, or less-then half + Array.Copy(target, 0, target, i, target.Length - i) + new String(target) + [] let forall predicate (str:string) = diff --git a/src/fsharp/LanguageFeatures.fs b/src/fsharp/LanguageFeatures.fs index 214ed21d76d..051b025c0e7 100644 --- a/src/fsharp/LanguageFeatures.fs +++ b/src/fsharp/LanguageFeatures.fs @@ -58,17 +58,17 @@ type LanguageVersion (specifiedVersionAsString) = // F# 5.0 LanguageFeature.FixedIndexSlice3d4d, languageVersion50 - LanguageFeature.FromEndSlicing, languageVersion50 LanguageFeature.DotlessFloat32Literal, languageVersion50 + LanguageFeature.AndBang, languageVersion50 + LanguageFeature.NullableOptionalInterop, languageVersion50 + LanguageFeature.DefaultInterfaceMemberConsumption, languageVersion50 // F# preview - LanguageFeature.NameOf, previewVersion + LanguageFeature.FromEndSlicing, previewVersion LanguageFeature.OpenStaticClasses, previewVersion LanguageFeature.PackageManagement, previewVersion - LanguageFeature.AndBang, previewVersion - LanguageFeature.NullableOptionalInterop, previewVersion - LanguageFeature.DefaultInterfaceMemberConsumption, previewVersion LanguageFeature.WitnessPassing, previewVersion + LanguageFeature.NameOf, previewVersion ] let specified = @@ -80,7 +80,7 @@ type LanguageVersion (specifiedVersionAsString) = | "latestmajor" -> latestMajorVersion | "4.6" -> languageVersion46 | "4.7" -> languageVersion47 -(* | "5.0" -> languageVersion50 *) + | "5.0" -> languageVersion50 | _ -> 0m let versionToString v = diff --git a/src/fsharp/pars.fsy b/src/fsharp/pars.fsy index 28d9e9df8d9..3a035bcdf0e 100644 --- a/src/fsharp/pars.fsy +++ b/src/fsharp/pars.fsy @@ -2702,7 +2702,7 @@ localBinding: let mRhs = expr.Range let optReturnType = $4 let bindingBuilder, mBindLhs = $3 - let localBindingRange = unionRanges (rhs2 parseState 3 5) mRhs + let localBindingRange = unionRanges (rhs2 parseState 1 5) mRhs let localBindingBuilder = (fun attrs vis mLetKwd -> let mWhole = unionRanges mLetKwd mRhs @@ -2711,7 +2711,7 @@ localBinding: localBindingRange, localBindingBuilder } | opt_inline opt_mutable bindingPattern opt_topReturnTypeWithTypeConstraints EQUALS error - { let mWhole = rhs2 parseState 3 5 + { let mWhole = rhs2 parseState 1 5 let mRhs = rhs parseState 5 let optReturnType = $4 let bindingBuilder, mBindLhs = $3 @@ -2726,7 +2726,7 @@ localBinding: | opt_inline opt_mutable bindingPattern opt_topReturnTypeWithTypeConstraints recover { if not $5 then reportParseErrorAt (rhs parseState 5) (FSComp.SR.parsUnexpectedEndOfFileDefinition()) let optReturnType = $4 - let mWhole = match optReturnType with None -> rhs parseState 3 | Some _ -> rhs2 parseState 3 4 + let mWhole = rhs2 parseState 1 (match optReturnType with None -> 3 | _ -> 4) let mRhs = mWhole.EndRange // zero-width range at end of last good token let bindingBuilder, mBindLhs = $3 let localBindingBuilder = diff --git a/src/fsharp/service/SemanticClassification.fs b/src/fsharp/service/SemanticClassification.fs index 367d2290122..f715f26349f 100644 --- a/src/fsharp/service/SemanticClassification.fs +++ b/src/fsharp/service/SemanticClassification.fs @@ -10,7 +10,6 @@ open FSharp.Compiler open FSharp.Compiler.AbstractIL.Internal.Library open FSharp.Compiler.Infos open FSharp.Compiler.ErrorLogger -open FSharp.Compiler.Lib open FSharp.Compiler.NameResolution open FSharp.Compiler.PrettyNaming open FSharp.Compiler.Range @@ -24,10 +23,12 @@ type SemanticClassificationType = | ReferenceType | ValueType | UnionCase + | UnionCaseField | Function | Property | MutableVar | Module + | NameSpace | Printf | ComputationExpression | IntrinsicFunction @@ -35,19 +36,34 @@ type SemanticClassificationType = | Interface | TypeArgument | Operator - | Disposable + | DisposableType + | DisposableValue + | Method + | ExtensionMethod + | ConstructorForReferenceType + | ConstructorForValueType + | Literal + | RecordField + | MutableRecordField + | RecordFieldAsFunction + | Exception + | Field + | Event + | Delegate + | NamedArgument + | Value + | LocalValue + | Type + | TypeDef [] module TcResolutionsExtensions = - let (|CNR|) (cnr:CapturedNameResolution) = (cnr.Item, cnr.ItemOccurence, cnr.DisplayEnv, cnr.NameResolutionEnv, cnr.AccessorDomain, cnr.Range) type TcResolutions with - member sResolutions.GetSemanticClassification(g: TcGlobals, amap: Import.ImportMap, formatSpecifierLocations: (range * int) [], range: range option) : struct(range * SemanticClassificationType) [] = - ErrorScope.Protect Range.range0 - (fun () -> + ErrorScope.Protect Range.range0 (fun () -> let (|LegitTypeOccurence|_|) = function | ItemOccurence.UseInType | ItemOccurence.UseInAttribute @@ -56,18 +72,13 @@ module TcResolutionsExtensions = | ItemOccurence.Pattern _ -> Some() | _ -> None - let (|OptionalArgumentAttribute|_|) ttype = - match ttype with - | TType.TType_app(tref, _) when tref.Stamp = g.attrib_OptionalArgumentAttribute.TyconRef.Stamp -> Some() - | _ -> None - let (|KeywordIntrinsicValue|_|) (vref: ValRef) = if valRefEq g g.raise_vref vref || - valRefEq g g.reraise_vref vref || - valRefEq g g.typeof_vref vref || - valRefEq g g.typedefof_vref vref || - valRefEq g g.sizeof_vref vref || - valRefEq g g.nameof_vref vref then Some() + valRefEq g g.reraise_vref vref || + valRefEq g g.typeof_vref vref || + valRefEq g g.typedefof_vref vref || + valRefEq g g.sizeof_vref vref || + valRefEq g g.nameof_vref vref then Some() else None let (|EnumCaseFieldInfo|_|) (rfinfo : RecdFieldInfo) = @@ -87,7 +98,15 @@ module TcResolutionsExtensions = sResolutions.CapturedNameResolutions :> seq<_> let isDisposableTy (ty: TType) = + not (typeEquiv g ty g.system_IDisposable_ty) && protectAssemblyExplorationNoReraise false false (fun () -> Infos.ExistsHeadTypeInEntireHierarchy g amap range0 ty g.tcref_System_IDisposable) + + let isDiscard (str: string) = str.StartsWith("_") + + let isValRefDisposable (vref: ValRef) = + not (isDiscard vref.DisplayName) && + // For values, we actually do want to color things if they literally are IDisposables + protectAssemblyExplorationNoReraise false false (fun () -> Infos.ExistsHeadTypeInEntireHierarchy g amap range0 vref.Type g.tcref_System_IDisposable) let isStructTyconRef (tyconRef: TyconRef) = let ty = generalizedTyconRef tyconRef @@ -116,61 +135,206 @@ module TcResolutionsExtensions = // 'seq' in 'seq { ... }' gets colored as keywords | (Item.Value vref), ItemOccurence.Use, _, _, _, m when valRefEq g g.seq_vref vref -> add m SemanticClassificationType.ComputationExpression + | (Item.Value vref), _, _, _, _, m when isValRefMutable vref -> add m SemanticClassificationType.MutableVar + | Item.Value KeywordIntrinsicValue, ItemOccurence.Use, _, _, _, m -> add m SemanticClassificationType.IntrinsicFunction + | (Item.Value vref), _, _, _, _, m when isFunction g vref.Type -> if valRefEq g g.range_op_vref vref || valRefEq g g.range_step_op_vref vref then () elif vref.IsPropertyGetterMethod || vref.IsPropertySetterMethod then add m SemanticClassificationType.Property + elif vref.IsMember then + add m SemanticClassificationType.Method elif IsOperatorName vref.DisplayName then add m SemanticClassificationType.Operator else add m SemanticClassificationType.Function - | Item.RecdField rfinfo, _, _, _, _, m when isRecdFieldMutable rfinfo -> - add m SemanticClassificationType.MutableVar - | Item.RecdField rfinfo, _, _, _, _, m when isFunction g rfinfo.FieldType -> - add m SemanticClassificationType.Function - | Item.RecdField EnumCaseFieldInfo, _, _, _, _, m -> - add m SemanticClassificationType.Enumeration - | Item.MethodGroup _, _, _, _, _, m -> - add m SemanticClassificationType.Function - // custom builders, custom operations get colored as keywords + + | (Item.Value vref), _, _, _, _, m -> + if isValRefDisposable vref then + add m SemanticClassificationType.DisposableValue + elif Option.isSome vref.LiteralValue then + add m SemanticClassificationType.Literal + elif not vref.IsCompiledAsTopLevel && not(isDiscard vref.DisplayName) then + add m SemanticClassificationType.LocalValue + else + add m SemanticClassificationType.Value + + | Item.RecdField rfinfo, _, _, _, _, m -> + match rfinfo with + | EnumCaseFieldInfo -> + add m SemanticClassificationType.Enumeration + | _ -> + if isRecdFieldMutable rfinfo then + add m SemanticClassificationType.MutableRecordField + elif isFunTy g rfinfo.FieldType then + add m SemanticClassificationType.RecordFieldAsFunction + else + add m SemanticClassificationType.RecordField + + | Item.AnonRecdField(_, tys, idx, m), _, _, _, _, _ -> + let ty = tys.[idx] + + // It's not currently possible for anon record fields to be mutable, but they can be ref cells + if isRefCellTy g ty then + add m SemanticClassificationType.MutableRecordField + elif isFunTy g ty then + add m SemanticClassificationType.RecordFieldAsFunction + else + add m SemanticClassificationType.RecordField + + | Item.Property (_, pinfo :: _), _, _, _, _, m -> + if not pinfo.IsIndexer then + add m SemanticClassificationType.Property + + | Item.CtorGroup (_, minfos), _, _, _, _, m -> + if minfos |> List.forall (fun minfo -> isDisposableTy minfo.ApparentEnclosingType) then + add m SemanticClassificationType.DisposableType + elif minfos |> List.forall (fun minfo -> isStructTy g minfo.ApparentEnclosingType) then + add m SemanticClassificationType.ConstructorForValueType + else + add m SemanticClassificationType.ConstructorForReferenceType + + | (Item.DelegateCtor _ | Item.FakeInterfaceCtor _), _, _, _, _, m -> + add m SemanticClassificationType.ConstructorForReferenceType + + | Item.MethodGroup (_, minfos, _), _, _, _, _, m -> + if minfos |> List.forall (fun minfo -> minfo.IsExtensionMember || minfo.IsCSharpStyleExtensionMember) then + add m SemanticClassificationType.ExtensionMethod + else + add m SemanticClassificationType.Method + | (Item.CustomBuilder _ | Item.CustomOperation _), ItemOccurence.Use, _, _, _, m -> add m SemanticClassificationType.ComputationExpression - // types get colored as types when they occur in syntactic types or custom attributes - // type variables get colored as types when they occur in syntactic types custom builders, custom operations get colored as keywords - | Item.Types (_, [OptionalArgumentAttribute]), LegitTypeOccurence, _, _, _, _ -> () - | Item.CtorGroup(_, [MethInfo.FSMeth(_, OptionalArgumentAttribute, _, _)]), LegitTypeOccurence, _, _, _, _ -> () - | Item.Types(_, types), LegitTypeOccurence, _, _, _, m when types |> List.exists (isInterfaceTy g) -> - add m SemanticClassificationType.Interface - | Item.Types(_, types), LegitTypeOccurence, _, _, _, m when types |> List.exists (isStructTy g) -> - add m SemanticClassificationType.ValueType + + // Special case measures for struct types | Item.Types(_, TType_app(tyconRef, TType_measure _ :: _) :: _), LegitTypeOccurence, _, _, _, m when isStructTyconRef tyconRef -> add m SemanticClassificationType.ValueType - | Item.Types(_, types), LegitTypeOccurence, _, _, _, m when types |> List.exists isDisposableTy -> - add m SemanticClassificationType.Disposable - | Item.Types _, LegitTypeOccurence, _, _, _, m -> - add m SemanticClassificationType.ReferenceType + + | Item.Types (_, ty :: _), LegitTypeOccurence, _, _, _, m -> + let reprToClassificationType repr tcref = + match repr with + | TFSharpObjectRepr om -> + match om.fsobjmodel_kind with + | TTyconClass -> SemanticClassificationType.ReferenceType + | TTyconInterface -> SemanticClassificationType.Interface + | TTyconStruct -> SemanticClassificationType.ValueType + | TTyconDelegate _ -> SemanticClassificationType.Delegate + | TTyconEnum _ -> SemanticClassificationType.Enumeration + | TRecdRepr _ + | TUnionRepr _ -> + if isStructTyconRef tcref then + SemanticClassificationType.ValueType + else + SemanticClassificationType.Type + | TILObjectRepr (TILObjectReprData (_, _, td)) -> + if td.IsClass then + SemanticClassificationType.ReferenceType + elif td.IsStruct then + SemanticClassificationType.ValueType + elif td.IsInterface then + SemanticClassificationType.Interface + elif td.IsEnum then + SemanticClassificationType.Enumeration + else + SemanticClassificationType.Delegate + | TAsmRepr _ -> SemanticClassificationType.TypeDef + | TMeasureableRepr _-> SemanticClassificationType.TypeDef +#if !NO_EXTENSIONTYPING + | TProvidedTypeExtensionPoint _-> SemanticClassificationType.TypeDef + | TProvidedNamespaceExtensionPoint _-> SemanticClassificationType.TypeDef +#endif + | TNoRepr -> SemanticClassificationType.ReferenceType + + let ty = stripTyEqns g ty + if isDisposableTy ty then + add m SemanticClassificationType.DisposableType + else + match tryTcrefOfAppTy g ty with + | ValueSome tcref -> + add m (reprToClassificationType tcref.TypeReprInfo tcref) + | ValueNone -> + if isStructTupleTy g ty then + add m SemanticClassificationType.ValueType + elif isRefTupleTy g ty then + add m SemanticClassificationType.ReferenceType + elif isFunction g ty then + add m SemanticClassificationType.Function + elif isTyparTy g ty then + add m SemanticClassificationType.ValueType + else + add m SemanticClassificationType.TypeDef + | (Item.TypeVar _ ), LegitTypeOccurence, _, _, _, m -> add m SemanticClassificationType.TypeArgument - | Item.UnqualifiedType tyconRefs, LegitTypeOccurence, _, _, _, m -> - if tyconRefs |> List.exists (fun tyconRef -> tyconRef.Deref.IsStructOrEnumTycon) then - add m SemanticClassificationType.ValueType - else add m SemanticClassificationType.ReferenceType - | Item.CtorGroup(_, minfos), LegitTypeOccurence, _, _, _, m -> - if minfos |> List.exists (fun minfo -> isStructTy g minfo.ApparentEnclosingType) then - add m SemanticClassificationType.ValueType - else add m SemanticClassificationType.ReferenceType + | Item.ExnCase _, LegitTypeOccurence, _, _, _, m -> - add m SemanticClassificationType.ReferenceType - | Item.ModuleOrNamespaces refs, LegitTypeOccurence, _, _, _, m when refs |> List.exists (fun x -> x.IsModule) -> - add m SemanticClassificationType.Module + add m SemanticClassificationType.Exception + + | Item.ModuleOrNamespaces (modref :: _), LegitTypeOccurence, _, _, _, m -> + if modref.IsNamespace then + add m SemanticClassificationType.NameSpace + else + add m SemanticClassificationType.Module + | (Item.ActivePatternCase _ | Item.UnionCase _ | Item.ActivePatternResult _), _, _, _, _, m -> add m SemanticClassificationType.UnionCase - | _ -> ()) + + | Item.UnionCaseField _, _, _, _, _, m -> + add m SemanticClassificationType.UnionCaseField + + | Item.ILField _, _, _, _, _, m -> + add m SemanticClassificationType.Field + + | Item.Event _, _, _, _, _, m -> + add m SemanticClassificationType.Event + + | (Item.ArgName _ | Item.SetterArg _), _, _, _, _, m -> + add m SemanticClassificationType.NamedArgument + + | Item.SetterArg _, _, _, _, _, m -> + add m SemanticClassificationType.Property + + | Item.UnqualifiedType (tcref :: _), LegitTypeOccurence, _, _, _, m -> + if tcref.IsEnumTycon || tcref.IsILEnumTycon then + add m SemanticClassificationType.Enumeration + elif tcref.IsExceptionDecl then + add m SemanticClassificationType.Exception + elif tcref.IsFSharpDelegateTycon then + add m SemanticClassificationType.Delegate + elif tcref.IsFSharpInterfaceTycon then + add m SemanticClassificationType.Interface + elif tcref.IsFSharpStructOrEnumTycon then + add m SemanticClassificationType.ValueType + elif tcref.IsModule then + add m SemanticClassificationType.Module + elif tcref.IsNamespace then + add m SemanticClassificationType.NameSpace + elif tcref.IsUnionTycon || tcref.IsRecordTycon then + if isStructTyconRef tcref then + add m SemanticClassificationType.ValueType + else + add m SemanticClassificationType.UnionCase + elif tcref.IsILTycon then + let (TILObjectReprData (_, _, tydef)) = tcref.ILTyconInfo + + if tydef.IsInterface then + add m SemanticClassificationType.Interface + elif tydef.IsDelegate then + add m SemanticClassificationType.Delegate + elif tydef.IsEnum then + add m SemanticClassificationType.Enumeration + elif tydef.IsStruct then + add m SemanticClassificationType.ValueType + else + add m SemanticClassificationType.ReferenceType + + | _ -> + ()) results.AddRange(formatSpecifierLocations |> Array.map (fun (m, _) -> struct(m, SemanticClassificationType.Printf))) results.ToArray() ) diff --git a/src/fsharp/service/SemanticClassification.fsi b/src/fsharp/service/SemanticClassification.fsi index ff0e89a29f8..f2447219bd6 100644 --- a/src/fsharp/service/SemanticClassification.fsi +++ b/src/fsharp/service/SemanticClassification.fsi @@ -2,7 +2,6 @@ namespace FSharp.Compiler.SourceCodeServices -open FSharp.Compiler open FSharp.Compiler.AccessibilityLogic open FSharp.Compiler.Import open FSharp.Compiler.NameResolution @@ -16,10 +15,12 @@ type SemanticClassificationType = | ReferenceType | ValueType | UnionCase + | UnionCaseField | Function | Property | MutableVar | Module + | NameSpace | Printf | ComputationExpression | IntrinsicFunction @@ -27,14 +28,30 @@ type SemanticClassificationType = | Interface | TypeArgument | Operator - | Disposable + | DisposableType + | DisposableValue + | Method + | ExtensionMethod + | ConstructorForReferenceType + | ConstructorForValueType + | Literal + | RecordField + | MutableRecordField + | RecordFieldAsFunction + | Exception + | Field + | Event + | Delegate + | NamedArgument + | Value + | LocalValue + | Type + | TypeDef /// Extension methods for the TcResolutions type. [] module internal TcResolutionsExtensions = - val (|CNR|) : cnr: CapturedNameResolution -> (Item * ItemOccurence * DisplayEnv * NameResolutionEnv * AccessorDomain * range) type TcResolutions with - member GetSemanticClassification: g: TcGlobals * amap: ImportMap * formatSpecifierLocations: (range * int) [] * range: range option -> struct(range * SemanticClassificationType) [] \ No newline at end of file diff --git a/src/fsharp/xlf/FSComp.txt.cs.xlf b/src/fsharp/xlf/FSComp.txt.cs.xlf index f7ae174868e..a176f81a800 100644 --- a/src/fsharp/xlf/FSComp.txt.cs.xlf +++ b/src/fsharp/xlf/FSComp.txt.cs.xlf @@ -138,8 +138,8 @@ - witness passing - witness passing + witness passing for trait constraints in F# quotations + witness passing for trait constraints in F# quotations diff --git a/src/fsharp/xlf/FSComp.txt.de.xlf b/src/fsharp/xlf/FSComp.txt.de.xlf index e086596e7b4..13a70ff59e1 100644 --- a/src/fsharp/xlf/FSComp.txt.de.xlf +++ b/src/fsharp/xlf/FSComp.txt.de.xlf @@ -138,8 +138,8 @@ - witness passing - witness passing + witness passing for trait constraints in F# quotations + witness passing for trait constraints in F# quotations diff --git a/src/fsharp/xlf/FSComp.txt.es.xlf b/src/fsharp/xlf/FSComp.txt.es.xlf index 1eb408ff3f1..48bcbb82529 100644 --- a/src/fsharp/xlf/FSComp.txt.es.xlf +++ b/src/fsharp/xlf/FSComp.txt.es.xlf @@ -138,8 +138,8 @@ - witness passing - witness passing + witness passing for trait constraints in F# quotations + witness passing for trait constraints in F# quotations diff --git a/src/fsharp/xlf/FSComp.txt.fr.xlf b/src/fsharp/xlf/FSComp.txt.fr.xlf index 15bc9610834..ed34481d69b 100644 --- a/src/fsharp/xlf/FSComp.txt.fr.xlf +++ b/src/fsharp/xlf/FSComp.txt.fr.xlf @@ -138,8 +138,8 @@ - witness passing - witness passing + witness passing for trait constraints in F# quotations + witness passing for trait constraints in F# quotations diff --git a/src/fsharp/xlf/FSComp.txt.it.xlf b/src/fsharp/xlf/FSComp.txt.it.xlf index 41a4e672b8d..28af1801f19 100644 --- a/src/fsharp/xlf/FSComp.txt.it.xlf +++ b/src/fsharp/xlf/FSComp.txt.it.xlf @@ -138,8 +138,8 @@ - witness passing - witness passing + witness passing for trait constraints in F# quotations + witness passing for trait constraints in F# quotations diff --git a/src/fsharp/xlf/FSComp.txt.ja.xlf b/src/fsharp/xlf/FSComp.txt.ja.xlf index 1dd7c03f820..7251c15f4b7 100644 --- a/src/fsharp/xlf/FSComp.txt.ja.xlf +++ b/src/fsharp/xlf/FSComp.txt.ja.xlf @@ -138,8 +138,8 @@ - witness passing - witness passing + witness passing for trait constraints in F# quotations + witness passing for trait constraints in F# quotations diff --git a/src/fsharp/xlf/FSComp.txt.ko.xlf b/src/fsharp/xlf/FSComp.txt.ko.xlf index b20e9912bbb..197d8985f0c 100644 --- a/src/fsharp/xlf/FSComp.txt.ko.xlf +++ b/src/fsharp/xlf/FSComp.txt.ko.xlf @@ -138,8 +138,8 @@ - witness passing - witness passing + witness passing for trait constraints in F# quotations + witness passing for trait constraints in F# quotations diff --git a/src/fsharp/xlf/FSComp.txt.pl.xlf b/src/fsharp/xlf/FSComp.txt.pl.xlf index c05715de16d..790649874ef 100644 --- a/src/fsharp/xlf/FSComp.txt.pl.xlf +++ b/src/fsharp/xlf/FSComp.txt.pl.xlf @@ -138,8 +138,8 @@ - witness passing - witness passing + witness passing for trait constraints in F# quotations + witness passing for trait constraints in F# quotations diff --git a/src/fsharp/xlf/FSComp.txt.pt-BR.xlf b/src/fsharp/xlf/FSComp.txt.pt-BR.xlf index 1e0e527e15f..dd5d94d1b92 100644 --- a/src/fsharp/xlf/FSComp.txt.pt-BR.xlf +++ b/src/fsharp/xlf/FSComp.txt.pt-BR.xlf @@ -138,8 +138,8 @@ - witness passing - witness passing + witness passing for trait constraints in F# quotations + witness passing for trait constraints in F# quotations diff --git a/src/fsharp/xlf/FSComp.txt.ru.xlf b/src/fsharp/xlf/FSComp.txt.ru.xlf index 21cef4e9e7e..33533871d5a 100644 --- a/src/fsharp/xlf/FSComp.txt.ru.xlf +++ b/src/fsharp/xlf/FSComp.txt.ru.xlf @@ -138,8 +138,8 @@ - witness passing - witness passing + witness passing for trait constraints in F# quotations + witness passing for trait constraints in F# quotations diff --git a/src/fsharp/xlf/FSComp.txt.tr.xlf b/src/fsharp/xlf/FSComp.txt.tr.xlf index 136b9f3b8f5..17cd35566de 100644 --- a/src/fsharp/xlf/FSComp.txt.tr.xlf +++ b/src/fsharp/xlf/FSComp.txt.tr.xlf @@ -138,8 +138,8 @@ - witness passing - witness passing + witness passing for trait constraints in F# quotations + witness passing for trait constraints in F# quotations diff --git a/src/fsharp/xlf/FSComp.txt.zh-Hans.xlf b/src/fsharp/xlf/FSComp.txt.zh-Hans.xlf index 0a1d50ac1bb..301dcb082af 100644 --- a/src/fsharp/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/fsharp/xlf/FSComp.txt.zh-Hans.xlf @@ -138,8 +138,8 @@ - witness passing - witness passing + witness passing for trait constraints in F# quotations + witness passing for trait constraints in F# quotations diff --git a/src/fsharp/xlf/FSComp.txt.zh-Hant.xlf b/src/fsharp/xlf/FSComp.txt.zh-Hant.xlf index 3da0fb2cca2..39a787c7103 100644 --- a/src/fsharp/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/fsharp/xlf/FSComp.txt.zh-Hant.xlf @@ -138,8 +138,8 @@ - witness passing - witness passing + witness passing for trait constraints in F# quotations + witness passing for trait constraints in F# quotations diff --git a/tests/Directory.Build.targets b/tests/Directory.Build.targets index 6df5fdfa9c7..1108759d4a2 100644 --- a/tests/Directory.Build.targets +++ b/tests/Directory.Build.targets @@ -3,13 +3,11 @@ - - diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/AccessOfTypeAbbreviationTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/AccessOfTypeAbbreviationTests.fs new file mode 100644 index 00000000000..416c62d63f6 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/AccessOfTypeAbbreviationTests.fs @@ -0,0 +1,75 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace FSharp.Compiler.ErrorMessages.ComponentTests + +open Xunit +open FSharp.Test.Utilities +open FSharp.Compiler.SourceCodeServices + +module ``Access Of Type Abbreviation`` = + + [] + let ``Private type produces warning when trying to export``() = + CompilerAssert.TypeCheckSingleError + """ +module Library = + type private Hidden = Hidden of unit + type Exported = Hidden + """ + FSharpErrorSeverity.Warning + 44 + (4, 8, 4, 16) + ("This construct is deprecated. The type 'Hidden' is less accessible than the value, member or type 'Exported' it is used in." + System.Environment.NewLine + "As of F# 4.1, the accessibility of type abbreviations is checked at compile-time. Consider changing the accessibility of the type abbreviation. Ignoring this warning might lead to runtime errors.") + + [] + let ``Internal type passes when abbrev is internal``() = + CompilerAssert.Pass + """ +module Library = + type internal Hidden = Hidden of unit + type internal Exported = Hidden + """ + + [] + let ``Internal type produces warning when trying to export``() = + CompilerAssert.TypeCheckSingleError + """ +module Library = + type internal Hidden = Hidden of unit + type Exported = Hidden + """ + FSharpErrorSeverity.Warning + 44 + (4, 8, 4, 16) + ("This construct is deprecated. The type 'Hidden' is less accessible than the value, member or type 'Exported' it is used in." + System.Environment.NewLine + "As of F# 4.1, the accessibility of type abbreviations is checked at compile-time. Consider changing the accessibility of the type abbreviation. Ignoring this warning might lead to runtime errors.") + + [] + let ``Private type produces warning when abbrev is internal``() = + CompilerAssert.TypeCheckSingleError + """ +module Library = + type private Hidden = Hidden of unit + type internal Exported = Hidden + """ + FSharpErrorSeverity.Warning + 44 + (4, 17, 4, 25) + ("This construct is deprecated. The type 'Hidden' is less accessible than the value, member or type 'Exported' it is used in." + System.Environment.NewLine + "As of F# 4.1, the accessibility of type abbreviations is checked at compile-time. Consider changing the accessibility of the type abbreviation. Ignoring this warning might lead to runtime errors.") + + [] + let ``Private type passes when abbrev is private``() = + CompilerAssert.Pass + """ +module Library = + type private Hidden = Hidden of unit + type private Exported = Hidden + """ + + [] + let ``Default access type passes when abbrev is default``() = + CompilerAssert.Pass + """ +module Library = + type Hidden = Hidden of unit + type Exported = Hidden + """ diff --git a/tests/fsharp/Compiler/ErrorMessages/AssignmentErrorTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/AssignmentErrorTests.fs similarity index 86% rename from tests/fsharp/Compiler/ErrorMessages/AssignmentErrorTests.fs rename to tests/FSharp.Compiler.ComponentTests/ErrorMessages/AssignmentErrorTests.fs index c1226c4ff93..f2f598d9dba 100644 --- a/tests/fsharp/Compiler/ErrorMessages/AssignmentErrorTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/AssignmentErrorTests.fs @@ -1,15 +1,15 @@ // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. -namespace FSharp.Compiler.UnitTests +namespace FSharp.Compiler.ErrorMessages.ComponentTests -open NUnit.Framework +open Xunit open FSharp.Test.Utilities open FSharp.Compiler.SourceCodeServices -[] + module ``Errors assigning to mutable objects`` = - [] + [] let ``Assign to immutable error``() = CompilerAssert.TypeCheckSingleError """ diff --git a/tests/fsharp/Compiler/ErrorMessages/ClassesTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ClassesTests.fs similarity index 82% rename from tests/fsharp/Compiler/ErrorMessages/ClassesTests.fs rename to tests/FSharp.Compiler.ComponentTests/ErrorMessages/ClassesTests.fs index f02837ef0c3..a51e92ed944 100644 --- a/tests/fsharp/Compiler/ErrorMessages/ClassesTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ClassesTests.fs @@ -1,15 +1,14 @@ // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. -namespace FSharp.Compiler.UnitTests +namespace FSharp.Compiler.ErrorMessages.ComponentTests -open NUnit.Framework +open Xunit open FSharp.Test.Utilities open FSharp.Compiler.SourceCodeServices -[] module ``Classes`` = - [] + [] let ``Tuple In Abstract Method``() = CompilerAssert.TypeCheckWithErrors """ @@ -27,7 +26,7 @@ let x = FSharpErrorSeverity.Error, 783, (6, 9, 6, 19), "At least one override did not correctly implement its corresponding abstract member" |] - [] + [] let ``Wrong Arity``() = CompilerAssert.TypeCheckSingleError """ @@ -43,7 +42,7 @@ MyType.MyMember("", 0, 0) (7, 1, 7, 26) "A member or object constructor 'MyMember' taking 3 arguments is not accessible from this code location. All accessible versions of method 'MyMember' take 2 arguments." - [] + [] let ``Method Is Not Static``() = CompilerAssert.TypeCheckSingleError """ @@ -57,7 +56,7 @@ let x = Class1.X() (5, 9, 5, 17) "Method or object constructor 'X' is not static" - [] + [] let ``Matching Method With Same Name Is Not Abstract``() = CompilerAssert.TypeCheckWithErrors """ @@ -75,7 +74,7 @@ let foo = FSharpErrorSeverity.Error, 783, (6, 11, 6, 14), "At least one override did not correctly implement its corresponding abstract member" |] - [] + [] let ``No Matching Abstract Method With Same Name``() = CompilerAssert.TypeCheckWithErrors """ @@ -89,13 +88,13 @@ let x = } """ [| - FSharpErrorSeverity.Error, 767, (8, 14, 8, 34), "The member 'Function' does not correspond to any abstract or virtual method available to override or implement. Maybe you want one of the following:\r\n MyFunction" + FSharpErrorSeverity.Error, 767, (8, 14, 8, 34), "The member 'Function' does not correspond to any abstract or virtual method available to override or implement. Maybe you want one of the following:" + System.Environment.NewLine + " MyFunction" FSharpErrorSeverity.Error, 17, (8, 19, 8, 27), "The member 'Function : 'a * 'b -> unit' does not have the correct type to override any given virtual method" - FSharpErrorSeverity.Error, 366, (7, 3, 9, 4), "No implementation was given for those members: \r\n\t'abstract member IInterface.MyFunction : int32 * int32 -> unit'\r\n\t'abstract member IInterface.SomeOtherFunction : int32 * int32 -> unit'\r\nNote that all interface members must be implemented and listed under an appropriate 'interface' declaration, e.g. 'interface ... with member ...'." + FSharpErrorSeverity.Error, 366, (7, 3, 9, 4), "No implementation was given for those members: " + System.Environment.NewLine + "\t'abstract member IInterface.MyFunction : int32 * int32 -> unit'" + System.Environment.NewLine + "\t'abstract member IInterface.SomeOtherFunction : int32 * int32 -> unit'" + System.Environment.NewLine + "Note that all interface members must be implemented and listed under an appropriate 'interface' declaration, e.g. 'interface ... with member ...'." FSharpErrorSeverity.Error, 783, (7, 9, 7, 19), "At least one override did not correctly implement its corresponding abstract member" |] - [] + [] let ``Member Has Multiple Possible Dispatch Slots``() = CompilerAssert.TypeCheckWithErrors """ @@ -108,11 +107,11 @@ type Overload = override __.Bar _ = 1 """ [| - FSharpErrorSeverity.Error, 366, (7, 15, 7, 24), "No implementation was given for those members: \r\n\t'abstract member IOverload.Bar : double -> int'\r\n\t'abstract member IOverload.Bar : int -> int'\r\nNote that all interface members must be implemented and listed under an appropriate 'interface' declaration, e.g. 'interface ... with member ...'." - FSharpErrorSeverity.Error, 3213, (8, 21, 8, 24), "The member 'Bar<'a0> : 'a0 -> int' matches multiple overloads of the same method.\nPlease restrict it to one of the following:\r\n Bar : double -> int\r\n Bar : int -> int." + FSharpErrorSeverity.Error, 366, (7, 15, 7, 24), "No implementation was given for those members: " + System.Environment.NewLine + "\t'abstract member IOverload.Bar : double -> int'" + System.Environment.NewLine + "\t'abstract member IOverload.Bar : int -> int'" + System.Environment.NewLine + "Note that all interface members must be implemented and listed under an appropriate 'interface' declaration, e.g. 'interface ... with member ...'." + FSharpErrorSeverity.Error, 3213, (8, 21, 8, 24), "The member 'Bar<'a0> : 'a0 -> int' matches multiple overloads of the same method.\nPlease restrict it to one of the following:" + System.Environment.NewLine + " Bar : double -> int" + System.Environment.NewLine + " Bar : int -> int." |] - [] + [] let ``Do Cannot Have Visibility Declarations``() = CompilerAssert.ParseWithErrors """ diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ConfusingTypeName.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ConfusingTypeName.fs new file mode 100644 index 00000000000..b67a75ec601 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ConfusingTypeName.fs @@ -0,0 +1,67 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace FSharp.Compiler.ErrorMessages.ComponentTests + +open Xunit +open FSharp.Test.Utilities +open FSharp.Test.Utilities.Utilities +open FSharp.Compiler.SourceCodeServices + +module ``Confusing Type Name`` = + + [] + let ``Checks expected types with multiple references``() = + let csLibAB = """ +public class A { } +public class B { } + """ + let csLibACmpl = + CompilationUtil.CreateCSharpCompilation(csLibAB, CSharpLanguageVersion.CSharp8, TargetFramework.NetCoreApp30, name = "libA") + |> CompilationReference.Create + + let csLibBCmpl = + CompilationUtil.CreateCSharpCompilation(csLibAB, CSharpLanguageVersion.CSharp8, TargetFramework.NetCoreApp30, name = "libB") + |> CompilationReference.Create + + let fsLibC = """ +module AMaker +let makeA () : A = A() +let makeB () = B<_>() + """ + + let fsLibD = """ +module OtherAMaker +let makeOtherA () : A = A() +let makeOtherB () = B<_>() + """ + + let fsLibCCmpl = + Compilation.Create(fsLibC, Fs, Library, cmplRefs = [csLibACmpl], name = "libC") + |> CompilationReference.CreateFSharp + + let fsLibDCmpl = + Compilation.Create(fsLibD, Fs, Library, cmplRefs = [csLibBCmpl], name = "libD") + |> CompilationReference.CreateFSharp + + let app = """ +module ConfusingTypeName +let a = AMaker.makeA() +let otherA = OtherAMaker.makeOtherA() +printfn "%A %A" (a.GetType().AssemblyQualifiedName) (otherA.GetType().AssemblyQualifiedName) +printfn "%A" (a = otherA) + +let b = AMaker.makeB() +let otherB = OtherAMaker.makeOtherB() +printfn "%A %A" (b.GetType().AssemblyQualifiedName) (otherB.GetType().AssemblyQualifiedName) +printfn "%A" (b = otherB) + """ + + let appCmpl = + Compilation.Create(app, Fs, Library, cmplRefs = [csLibACmpl; csLibBCmpl; fsLibCCmpl; fsLibDCmpl]) + + CompilerAssert.CompileWithErrors( + appCmpl, + [| + (FSharpErrorSeverity.Error, 1, (6, 19, 6, 25), ("This expression was expected to have type\n 'A (libA, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null)' \nbut here has type\n 'A (libB, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null)' ")) + (FSharpErrorSeverity.Error, 1, (11, 19, 11, 25), ("This expression was expected to have type\n 'B (libA, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null)' \nbut here has type\n 'B (libB, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null)' ")) + |], true) diff --git a/tests/fsharp/Compiler/ErrorMessages/ConstructorTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ConstructorTests.fs similarity index 88% rename from tests/fsharp/Compiler/ErrorMessages/ConstructorTests.fs rename to tests/FSharp.Compiler.ComponentTests/ErrorMessages/ConstructorTests.fs index be7e5823391..c9636e711a5 100644 --- a/tests/fsharp/Compiler/ErrorMessages/ConstructorTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ConstructorTests.fs @@ -1,29 +1,27 @@ // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. -namespace FSharp.Compiler.UnitTests +namespace FSharp.Compiler.ErrorMessages.ComponentTests -open NUnit.Framework +open Xunit open FSharp.Test.Utilities open FSharp.Compiler.SourceCodeServices -[] module ``Constructor`` = - [] + [] let ``Invalid Record``() = CompilerAssert.TypeCheckWithErrors """ type Record = {field1:int; field2:int} let doSomething (xs) = List.map (fun {field1=x} -> x) xs - doSomething {Record.field1=0; field2=0} """ [| - FSharpErrorSeverity.Error, 1, (5, 13, 5, 40), "This expression was expected to have type\n 'Record list' \nbut here has type\n 'Record' " - FSharpErrorSeverity.Warning, 20, (5, 1, 5, 40), "The result of this expression has type 'int list' and is implicitly ignored. Consider using 'ignore' to discard this value explicitly, e.g. 'expr |> ignore', or 'let' to bind the result to a name, e.g. 'let result = expr'." + FSharpErrorSeverity.Error, 1, (4, 13, 4, 40), "This expression was expected to have type\n 'Record list' \nbut here has type\n 'Record' " + FSharpErrorSeverity.Warning, 20, (4, 1, 4, 40), "The result of this expression has type 'int list' and is implicitly ignored. Consider using 'ignore' to discard this value explicitly, e.g. 'expr |> ignore', or 'let' to bind the result to a name, e.g. 'let result = expr'." |] - [] + [] let ``Comma In Rec Ctor``() = CompilerAssert.TypeCheckWithErrors """ @@ -31,11 +29,11 @@ type Person = { Name : string; Age : int; City : string } let x = { Name = "Isaac", Age = 21, City = "London" } """ [| - FSharpErrorSeverity.Error, 1, (3, 18, 3, 52), "This expression was expected to have type\n 'string' \nbut here has type\n ''a * 'b * 'c' \r\nA ';' is used to separate field values in records. Consider replacing ',' with ';'." + FSharpErrorSeverity.Error, 1, (3, 18, 3, 52), "This expression was expected to have type\n 'string' \nbut here has type\n ''a * 'b * 'c' " + System.Environment.NewLine + "A ';' is used to separate field values in records. Consider replacing ',' with ';'." FSharpErrorSeverity.Error, 764, (3, 9, 3, 54), "No assignment given for field 'Age' of type 'Test.Person'" |] - [] + [] let ``Missing Comma In Ctor``() = CompilerAssert.TypeCheckWithErrors """ @@ -48,13 +46,13 @@ let p = Age = 18) """ [| - FSharpErrorSeverity.Error, 39, (7, 12, 7, 16), "The value or constructor 'Name' is not defined. Maybe you want one of the following:\r\n nan" + FSharpErrorSeverity.Error, 39, (7, 12, 7, 16), "The value or constructor 'Name' is not defined. Maybe you want one of the following:" + System.Environment.NewLine + " nan" FSharpErrorSeverity.Warning, 20, (7, 12, 7, 25), "The result of this equality expression has type 'bool' and is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'." FSharpErrorSeverity.Error, 39, (8, 12, 8, 15), "The value or constructor 'Age' is not defined." FSharpErrorSeverity.Error, 501, (7, 5, 8, 21), "The object constructor 'Person' takes 0 argument(s) but is here given 1. The required signature is 'new : unit -> Person'. If some of the arguments are meant to assign values to properties, consider separating those arguments with a comma (',')." |] - [] + [] let ``Missing Ctor Value``() = CompilerAssert.TypeCheckSingleError """ @@ -71,7 +69,7 @@ let p = (7, 5, 8, 21) "The member or object constructor 'Person' requires 1 argument(s). The required signature is 'new : x:int -> Person'." - [] + [] let ``Extra Argument In Ctor``() = CompilerAssert.TypeCheckSingleError """ @@ -87,7 +85,7 @@ let p = (7, 5, 7, 14) "The object constructor 'Person' takes 0 argument(s) but is here given 1. The required signature is 'new : unit -> Person'." - [] + [] let ``Extra Argument In Ctor2``() = CompilerAssert.TypeCheckSingleError """ @@ -105,7 +103,7 @@ let p = (9, 5, 9, 16) "The object constructor 'Person' takes 0 argument(s) but is here given 1. The required signature is 'new : unit -> Person'." - [] + [] let ``Valid Comma In Rec Ctor``() = CompilerAssert.Pass """ diff --git a/tests/fsharp/Compiler/ErrorMessages/DontSuggestTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/DontSuggestTests.fs similarity index 84% rename from tests/fsharp/Compiler/ErrorMessages/DontSuggestTests.fs rename to tests/FSharp.Compiler.ComponentTests/ErrorMessages/DontSuggestTests.fs index f7b3cc2cb05..13a6f6b0dcc 100644 --- a/tests/fsharp/Compiler/ErrorMessages/DontSuggestTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/DontSuggestTests.fs @@ -1,15 +1,14 @@ // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. -namespace FSharp.Compiler.UnitTests +namespace FSharp.Compiler.ErrorMessages.ComponentTests -open NUnit.Framework +open Xunit open FSharp.Test.Utilities open FSharp.Compiler.SourceCodeServices -[] module ``Don't Suggest`` = - [] + [] let ``Dont Suggest Completely Wrong Stuff``() = CompilerAssert.TypeCheckSingleError """ @@ -18,9 +17,9 @@ let _ = Path.GetFullPath "images" FSharpErrorSeverity.Error 39 (2, 9, 2, 13) - "The value, namespace, type or module 'Path' is not defined. Maybe you want one of the following:\r\n Math" + ("The value, namespace, type or module 'Path' is not defined. Maybe you want one of the following:" + System.Environment.NewLine + " Math") - [] + [] let ``Dont Suggest When Things Are Open``() = CompilerAssert.ParseWithErrors """ @@ -37,7 +36,7 @@ let x = N. FSharpErrorSeverity.Error, 222, (2, 1, 3, 1), "Files in libraries or multiple-file applications must begin with a namespace or module declaration. When using a module declaration at the start of a file the '=' sign is not allowed. If this is a top-level module, consider removing the = to resolve this error." |] - [] + [] let ``Dont Suggest Intentionally Unused Variables``() = CompilerAssert.TypeCheckSingleError """ diff --git a/tests/fsharp/Compiler/ErrorMessages/ElseBranchHasWrongTypeTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ElseBranchHasWrongTypeTests.fs similarity index 96% rename from tests/fsharp/Compiler/ErrorMessages/ElseBranchHasWrongTypeTests.fs rename to tests/FSharp.Compiler.ComponentTests/ErrorMessages/ElseBranchHasWrongTypeTests.fs index ed5b9a44863..54d5c41a68c 100644 --- a/tests/fsharp/Compiler/ErrorMessages/ElseBranchHasWrongTypeTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ElseBranchHasWrongTypeTests.fs @@ -1,15 +1,15 @@ // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. -namespace FSharp.Compiler.UnitTests +namespace FSharp.Compiler.ErrorMessages.ComponentTests -open NUnit.Framework +open Xunit open FSharp.Test.Utilities open FSharp.Compiler.SourceCodeServices -[] + module ``Else branch has wrong type`` = - [] + [] let ``Else branch is int while if branch is string``() = CompilerAssert.TypeCheckSingleError """ @@ -23,7 +23,7 @@ let y = (5, 10, 5, 13) "All branches of an 'if' expression must return values of the same type as the first branch, which here is 'string'. This branch returns a value of type 'int'." - [] + [] let ``Else branch is a function that returns int while if branch is string``() = CompilerAssert.TypeCheckSingleError """ @@ -39,7 +39,7 @@ let y = "All branches of an 'if' expression must return values of the same type as the first branch, which here is 'string'. This branch returns a value of type 'int'." - [] + [] let ``Else branch is a sequence of expressions that returns int while if branch is string``() = CompilerAssert.TypeCheckSingleError """ @@ -58,7 +58,7 @@ let y = "All branches of an 'if' expression must return values of the same type as the first branch, which here is 'string'. This branch returns a value of type 'int'." - [] + [] let ``Else branch is a longer sequence of expressions that returns int while if branch is string``() = CompilerAssert.TypeCheckSingleError """ @@ -79,7 +79,7 @@ let y = "All branches of an 'if' expression must return values of the same type as the first branch, which here is 'string'. This branch returns a value of type 'int'." - [] + [] let ``Else branch context doesn't propagate into function application``() = CompilerAssert.TypeCheckSingleError """ @@ -95,7 +95,7 @@ let y = (7, 11, 7, 14) "This expression was expected to have type\n 'string' \nbut here has type\n 'int' " - [] + [] let ``Else branch context doesn't propagate into function application even if not last expr``() = CompilerAssert.TypeCheckSingleError """ @@ -112,7 +112,7 @@ let y = (7, 11, 7, 14) "This expression was expected to have type\n 'string' \nbut here has type\n 'int' " - [] + [] let ``Else branch context doesn't propagate into for loop``() = CompilerAssert.TypeCheckSingleError """ @@ -131,7 +131,7 @@ let y = (7, 14, 7, 22) "This expression was expected to have type\n 'int' \nbut here has type\n 'string' " - [] + [] let ``Else branch context doesn't propagate to lines before last line``() = CompilerAssert.TypeCheckSingleError """ @@ -149,7 +149,7 @@ let y = (7, 22, 7, 23) "This expression was expected to have type\n 'string' \nbut here has type\n 'int' " - [] + [] let ``Else branch should not have wrong context type``() = CompilerAssert.TypeCheckWithErrors """ @@ -162,7 +162,7 @@ let y : bool = FSharpErrorSeverity.Error, 1, (5, 10, 5, 13), "All branches of an 'if' expression must return values of the same type as the first branch, which here is 'bool'. This branch returns a value of type 'string'." |] - [] + [] let ``Else branch has wrong type in nested if``() = CompilerAssert.TypeCheckWithErrors """ diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/InvalidNumericLiteralTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/InvalidNumericLiteralTests.fs index c6631ab629e..a20dd899762 100644 --- a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/InvalidNumericLiteralTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/InvalidNumericLiteralTests.fs @@ -1,12 +1,12 @@ // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. -namespace FSharp.Compiler.ComponentTests +namespace FSharp.Compiler.ErrorMessages.ComponentTests open Xunit open FSharp.Test.Utilities open FSharp.Compiler.SourceCodeServices -module ``Invalid Numeric Literal`` = +module ``Numeric Literals`` = [] let ``1up is invalid Numeric Literal``() = diff --git a/tests/fsharp/Compiler/ErrorMessages/MissingElseBranch.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/MissingElseBranch.fs similarity index 93% rename from tests/fsharp/Compiler/ErrorMessages/MissingElseBranch.fs rename to tests/FSharp.Compiler.ComponentTests/ErrorMessages/MissingElseBranch.fs index 370b4c24053..9ab09f8a9ea 100644 --- a/tests/fsharp/Compiler/ErrorMessages/MissingElseBranch.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/MissingElseBranch.fs @@ -1,15 +1,14 @@ // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. -namespace FSharp.Compiler.UnitTests +namespace FSharp.Compiler.ErrorMessages.ComponentTests -open NUnit.Framework +open Xunit open FSharp.Test.Utilities open FSharp.Compiler.SourceCodeServices -[] module ``Else branch is missing`` = - [] + [] let ``Fail if else branch is missing``() = CompilerAssert.TypeCheckSingleError """ @@ -22,7 +21,7 @@ let y = (4, 19, 4, 25) "This 'if' expression is missing an 'else' branch. Because 'if' is an expression, and not a statement, add an 'else' branch which also returns a value of type 'string'." - [] + [] let ``Fail on type error in condition``() = CompilerAssert.TypeCheckSingleError """ @@ -37,7 +36,7 @@ let y = (5, 14, 5, 20) "This expression was expected to have type\n 'int' \nbut here has type\n 'string' " - [] + [] let ``Fail if else branch is missing in nesting``() = CompilerAssert.TypeCheckSingleError """ diff --git a/tests/fsharp/Compiler/ErrorMessages/MissingExpressionTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/MissingExpressionTests.fs similarity index 89% rename from tests/fsharp/Compiler/ErrorMessages/MissingExpressionTests.fs rename to tests/FSharp.Compiler.ComponentTests/ErrorMessages/MissingExpressionTests.fs index b00833e418a..802bcfd6750 100644 --- a/tests/fsharp/Compiler/ErrorMessages/MissingExpressionTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/MissingExpressionTests.fs @@ -1,15 +1,15 @@ // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. -namespace FSharp.Compiler.UnitTests +namespace FSharp.Compiler.ErrorMessages.ComponentTests -open NUnit.Framework +open Xunit open FSharp.Test.Utilities open FSharp.Compiler.SourceCodeServices -[] + module ``Missing Expression`` = - [] + [] let ``Missing Expression after let``() = CompilerAssert.TypeCheckSingleError """ diff --git a/tests/fsharp/Compiler/ErrorMessages/ModuleAbbreviationTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ModuleAbbreviationTests.fs similarity index 87% rename from tests/fsharp/Compiler/ErrorMessages/ModuleAbbreviationTests.fs rename to tests/FSharp.Compiler.ComponentTests/ErrorMessages/ModuleAbbreviationTests.fs index b67bb8ca8b5..5c9647fb070 100644 --- a/tests/fsharp/Compiler/ErrorMessages/ModuleAbbreviationTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ModuleAbbreviationTests.fs @@ -1,15 +1,15 @@ // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. -namespace FSharp.Compiler.UnitTests +namespace FSharp.Compiler.ErrorMessages.ComponentTests -open NUnit.Framework +open Xunit open FSharp.Test.Utilities open FSharp.Compiler.SourceCodeServices -[] + module ``Module Abbreviations`` = - [] + [] let ``Public Module Abbreviation``() = CompilerAssert.TypeCheckSingleError """ diff --git a/tests/fsharp/Compiler/ErrorMessages/NameResolutionTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/NameResolutionTests.fs similarity index 72% rename from tests/fsharp/Compiler/ErrorMessages/NameResolutionTests.fs rename to tests/FSharp.Compiler.ComponentTests/ErrorMessages/NameResolutionTests.fs index 4a94339fe18..c48a5c9113b 100644 --- a/tests/fsharp/Compiler/ErrorMessages/NameResolutionTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/NameResolutionTests.fs @@ -1,15 +1,14 @@ // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. -namespace FSharp.Compiler.UnitTests +namespace FSharp.Compiler.ErrorMessages.ComponentTests -open NUnit.Framework +open Xunit open FSharp.Test.Utilities open FSharp.Compiler.SourceCodeServices -[] module NameResolutionTests = - [] + [] let FieldNotInRecord () = CompilerAssert.TypeCheckSingleError """ @@ -25,9 +24,9 @@ let r:F = { Size=3; Height=4; Wall=1 } FSharpErrorSeverity.Error 1129 (9, 31, 9, 35) - "The record type 'F' does not contain a label 'Wall'. Maybe you want one of the following:\r\n Wallis" + ("The record type 'F' does not contain a label 'Wall'. Maybe you want one of the following:" + System.Environment.NewLine + " Wallis") - [] + [] let RecordFieldProposal () = CompilerAssert.TypeCheckSingleError """ @@ -43,4 +42,4 @@ let r = { Size=3; Height=4; Wall=1 } FSharpErrorSeverity.Error 39 (9, 29, 9, 33) - "The record label 'Wall' is not defined. Maybe you want one of the following:\r\n Walls\r\n Wallis" + ("The record label 'Wall' is not defined. Maybe you want one of the following:" + System.Environment.NewLine + " Walls" + System.Environment.NewLine + " Wallis") diff --git a/tests/fsharp/Compiler/ErrorMessages/SuggestionsTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/SuggestionsTests.fs similarity index 62% rename from tests/fsharp/Compiler/ErrorMessages/SuggestionsTests.fs rename to tests/FSharp.Compiler.ComponentTests/ErrorMessages/SuggestionsTests.fs index e6f44d2430f..bf26f8a2102 100644 --- a/tests/fsharp/Compiler/ErrorMessages/SuggestionsTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/SuggestionsTests.fs @@ -1,15 +1,14 @@ // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. -namespace FSharp.Compiler.UnitTests +namespace FSharp.Compiler.ErrorMessages.ComponentTests -open NUnit.Framework +open Xunit open FSharp.Test.Utilities open FSharp.Compiler.SourceCodeServices -[] module Suggestions = - [] + [] let ``Field Suggestion`` () = CompilerAssert.TypeCheckSingleError """ @@ -20,10 +19,10 @@ let x = { Person.Names = "Isaac" } FSharpErrorSeverity.Error 39 (4, 18, 4, 23) - "The type 'Person' does not define the field, constructor or member 'Names'. Maybe you want one of the following:\r\n Name" + ("The type 'Person' does not define the field, constructor or member 'Names'. Maybe you want one of the following:" + System.Environment.NewLine + " Name") - [] + [] let ``Suggest Array Module Functions`` () = CompilerAssert.TypeCheckSingleError """ @@ -33,10 +32,10 @@ let f = FSharpErrorSeverity.Error 39 (3, 11, 3, 14) - "The value, constructor, namespace or type 'blt' is not defined. Maybe you want one of the following:\r\n blit" + ("The value, constructor, namespace or type 'blt' is not defined. Maybe you want one of the following:" + System.Environment.NewLine + " blit") - [] + [] let ``Suggest Async Module`` () = CompilerAssert.TypeCheckSingleError """ @@ -46,10 +45,10 @@ let f = FSharpErrorSeverity.Error 39 (3, 5, 3, 9) - "The value, namespace, type or module 'Asnc' is not defined. Maybe you want one of the following:\r\n Async\r\n async\r\n asin\r\n snd" + ("The value, namespace, type or module 'Asnc' is not defined. Maybe you want one of the following:" + System.Environment.NewLine + " Async" + System.Environment.NewLine + " async" + System.Environment.NewLine + " asin" + System.Environment.NewLine + " snd") - [] + [] let ``Suggest Attribute`` () = CompilerAssert.TypeCheckSingleError """ @@ -61,10 +60,10 @@ type MyClass<'Bar>() = FSharpErrorSeverity.Error 39 (2, 3, 2, 15) - "The type 'AbstractClas' is not defined. Maybe you want one of the following:\r\n AbstractClass\r\n AbstractClassAttribute" + ("The type 'AbstractClas' is not defined. Maybe you want one of the following:" + System.Environment.NewLine + " AbstractClass" + System.Environment.NewLine + " AbstractClassAttribute") - [] + [] let ``Suggest Double Backtick Identifiers`` () = CompilerAssert.TypeCheckSingleError """ @@ -76,10 +75,10 @@ let x = N.``longe name`` FSharpErrorSeverity.Error 39 (5, 11, 5, 25) - "The value, constructor, namespace or type 'longe name' is not defined. Maybe you want one of the following:\r\n longer name" + ("The value, constructor, namespace or type 'longe name' is not defined. Maybe you want one of the following:" + System.Environment.NewLine + " longer name") - [] + [] let ``Suggest Double Backtick Unions`` () = CompilerAssert.TypeCheckSingleError """ @@ -95,10 +94,10 @@ let x = N.MyUnion.``My Case2`` FSharpErrorSeverity.Error 39 (9, 19, 9,31) - "The type 'MyUnion' does not define the field, constructor or member 'My Case2'. Maybe you want one of the following:\r\n My Case1\r\n Case2" + ("The type 'MyUnion' does not define the field, constructor or member 'My Case2'. Maybe you want one of the following:" + System.Environment.NewLine + " My Case1" + System.Environment.NewLine + " Case2") - [] + [] let ``Suggest Fields In Constructor`` () = CompilerAssert.TypeCheckSingleError """ @@ -112,10 +111,10 @@ let c = MyClass(Property = "") FSharpErrorSeverity.Error 495 (7, 17, 7, 25) - "The object constructor 'MyClass' has no argument or settable return property 'Property'. The required signature is new : unit -> MyClass. Maybe you want one of the following:\r\n MyProperty\r\n MyProperty2\r\n ABigProperty" + ("The object constructor 'MyClass' has no argument or settable return property 'Property'. The required signature is new : unit -> MyClass. Maybe you want one of the following:" + System.Environment.NewLine + " MyProperty" + System.Environment.NewLine + " MyProperty2" + System.Environment.NewLine + " ABigProperty") - [] + [] let ``Suggest Generic Type`` () = CompilerAssert.TypeCheckSingleError """ @@ -124,10 +123,10 @@ type T = System.Collections.Generic.Dictionary FSharpErrorSeverity.Error 39 (2, 48, 2, 53) - "The type 'int11' is not defined. Maybe you want one of the following:\r\n int16\r\n int16`1\r\n int8\r\n uint16\r\n int" + ("The type 'int11' is not defined. Maybe you want one of the following:" + System.Environment.NewLine + " int16" + System.Environment.NewLine + " int16`1" + System.Environment.NewLine + " int8" + System.Environment.NewLine + " uint16" + System.Environment.NewLine + " int") - [] + [] let ``Suggest Methods`` () = CompilerAssert.TypeCheckSingleError """ @@ -143,10 +142,10 @@ module Test2 = FSharpErrorSeverity.Error 39 (9, 7, 9, 14) - "The type 'D' does not define the field, constructor or member 'Method2'. Maybe you want one of the following:\r\n Method1" + ("The type 'D' does not define the field, constructor or member 'Method2'. Maybe you want one of the following:" + System.Environment.NewLine + " Method1") - [] + [] let ``Suggest Modules`` () = CompilerAssert.TypeCheckSingleError """ @@ -159,10 +158,10 @@ open Collectons FSharpErrorSeverity.Error 39 (6, 6, 6, 16) - "The namespace or module 'Collectons' is not defined. Maybe you want one of the following:\r\n Collections" + ("The namespace or module 'Collectons' is not defined. Maybe you want one of the following:" + System.Environment.NewLine + " Collections") - [] + [] let ``Suggest Namespaces`` () = CompilerAssert.TypeCheckSingleError """ @@ -174,7 +173,7 @@ open System.Collectons "The namespace 'Collectons' is not defined." - [] + [] let ``Suggest Record Labels`` () = CompilerAssert.TypeCheckSingleError """ @@ -187,10 +186,10 @@ let x = r.ello FSharpErrorSeverity.Error 39 (6, 11, 6, 15) - "The type 'MyRecord' does not define the field, constructor or member 'ello'. Maybe you want one of the following:\r\n Hello" + ("The type 'MyRecord' does not define the field, constructor or member 'ello'. Maybe you want one of the following:" + System.Environment.NewLine + " Hello") - [] + [] let ``Suggest Record Type for RequireQualifiedAccess Records`` () = CompilerAssert.TypeCheckSingleError """ @@ -205,10 +204,10 @@ let r = { Field1 = "hallo"; Field2 = 1 } FSharpErrorSeverity.Error 39 (8, 11, 8, 17) - "The record label 'Field1' is not defined. Maybe you want one of the following:\r\n MyRecord.Field1" + ("The record label 'Field1' is not defined. Maybe you want one of the following:" + System.Environment.NewLine + " MyRecord.Field1") - [] + [] let ``Suggest To Use Indexer`` () = CompilerAssert.TypeCheckWithErrors """ @@ -227,7 +226,7 @@ let a = (f())[1] |] - [] + [] let ``Suggest Type Parameters`` () = CompilerAssert.TypeCheckSingleError """ @@ -243,7 +242,7 @@ type MyClass<'Bar>() = "The type parameter 'B is not defined." - [] + [] let ``Suggest Types in Module`` () = CompilerAssert.TypeCheckSingleError """ @@ -252,9 +251,9 @@ let x : System.Collections.Generic.Lst = ResizeArray() FSharpErrorSeverity.Error 39 (2, 36, 2, 39) - "The type 'Lst' is not defined in 'System.Collections.Generic'. Maybe you want one of the following:\r\n List\r\n IList\r\n List`1" + ("The type 'Lst' is not defined in 'System.Collections.Generic'. Maybe you want one of the following:" + System.Environment.NewLine + " List" + System.Environment.NewLine + " IList" + System.Environment.NewLine + " List`1") - [] + [] let ``Suggest Types in Namespace`` () = CompilerAssert.TypeCheckSingleError """ @@ -263,10 +262,10 @@ let x = System.DateTie.MaxValue FSharpErrorSeverity.Error 39 (2, 16, 2, 23) - "The value, constructor, namespace or type 'DateTie' is not defined. Maybe you want one of the following:\r\n DateTime\r\n DateTimeKind\r\n DateTimeOffset\r\n Data" + ("The value, constructor, namespace or type 'DateTie' is not defined. Maybe you want one of the following:" + System.Environment.NewLine + " DateTime" + System.Environment.NewLine + " DateTimeKind" + System.Environment.NewLine + " DateTimeOffset" + System.Environment.NewLine + " Data") - [] + [] let ``Suggest Union Cases`` () = CompilerAssert.TypeCheckSingleError """ @@ -279,10 +278,10 @@ let u = MyUnion.AntherCase FSharpErrorSeverity.Error 39 (6, 17, 6, 27) - "The type 'MyUnion' does not define the field, constructor or member 'AntherCase'. Maybe you want one of the following:\r\n AnotherCase" + ("The type 'MyUnion' does not define the field, constructor or member 'AntherCase'. Maybe you want one of the following:" + System.Environment.NewLine + " AnotherCase") - [] + [] let ``Suggest Union Type for RequireQualifiedAccess Unions`` () = CompilerAssert.TypeCheckSingleError """ @@ -296,10 +295,10 @@ let x : MyUnion = MyCase1 FSharpErrorSeverity.Error 39 (7, 19, 7, 26) - "The value or constructor 'MyCase1' is not defined. Maybe you want one of the following:\r\n MyUnion.MyCase1" + ("The value or constructor 'MyCase1' is not defined. Maybe you want one of the following:" + System.Environment.NewLine + " MyUnion.MyCase1") - [] + [] let ``Suggest Unions in PatternMatch`` () = CompilerAssert.TypeCheckSingleError """ @@ -318,4 +317,4 @@ let x = FSharpErrorSeverity.Error 39 (11, 15, 11, 19) - "The type 'MyUnion' does not define the field, constructor or member 'Cas1'. Maybe you want one of the following:\r\n Case1\r\n Case2" + ("The type 'MyUnion' does not define the field, constructor or member 'Cas1'. Maybe you want one of the following:" + System.Environment.NewLine + " Case1" + System.Environment.NewLine + " Case2") diff --git a/tests/fsharp/Compiler/ErrorMessages/TypeMismatchTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/TypeMismatchTests.fs similarity index 84% rename from tests/fsharp/Compiler/ErrorMessages/TypeMismatchTests.fs rename to tests/FSharp.Compiler.ComponentTests/ErrorMessages/TypeMismatchTests.fs index 58557c82cd4..817e0a588c6 100644 --- a/tests/fsharp/Compiler/ErrorMessages/TypeMismatchTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/TypeMismatchTests.fs @@ -1,15 +1,14 @@ // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. -namespace FSharp.Compiler.UnitTests +namespace FSharp.Compiler.ErrorMessages.ComponentTests -open NUnit.Framework +open Xunit open FSharp.Test.Utilities open FSharp.Compiler.SourceCodeServices -[] module ``Type Mismatch`` = - [] + [] let ``return Instead Of return!``() = CompilerAssert.TypeCheckSingleError """ @@ -20,7 +19,7 @@ let rec foo() = async { return foo() } (2, 32, 2, 37) "Type mismatch. Expecting a\n ''a' \nbut given a\n 'Async<'a>' \nThe types ''a' and 'Async<'a>' cannot be unified. Consider using 'return!' instead of 'return'." - [] + [] let ``yield Instead Of yield!``() = CompilerAssert.TypeCheckSingleError """ @@ -34,7 +33,7 @@ let rec f () = Foo() { yield f ()} (5, 30, 5, 34) "Type mismatch. Expecting a\n ''a' \nbut given a\n ''a list' \nThe types ''a' and ''a list' cannot be unified. Consider using 'yield!' instead of 'yield'." - [] + [] let ``Ref Cell Instead Of Not``() = CompilerAssert.TypeCheckSingleError """ @@ -45,9 +44,9 @@ if !x then FSharpErrorSeverity.Error 1 (3, 5, 3, 6) - "This expression was expected to have type\n 'bool ref' \nbut here has type\n 'bool' \r\nThe '!' operator is used to dereference a ref cell. Consider using 'not expr' here." + ("This expression was expected to have type\n 'bool ref' \nbut here has type\n 'bool' " + System.Environment.NewLine + "The '!' operator is used to dereference a ref cell. Consider using 'not expr' here.") - [] + [] let ``Ref Cell Instead Of Not 2``() = CompilerAssert.TypeCheckSingleError """ @@ -57,9 +56,9 @@ let y = !x FSharpErrorSeverity.Error 1 (3, 10, 3, 11) - "This expression was expected to have type\n ''a ref' \nbut here has type\n 'bool' \r\nThe '!' operator is used to dereference a ref cell. Consider using 'not expr' here." + ("This expression was expected to have type\n ''a ref' \nbut here has type\n 'bool' " + System.Environment.NewLine + "The '!' operator is used to dereference a ref cell. Consider using 'not expr' here.") - [] + [] let ``Guard Has Wrong Type``() = CompilerAssert.TypeCheckWithErrors """ @@ -73,7 +72,7 @@ match x with FSharpErrorSeverity.Warning, 20, (3, 1, 5, 13), "The result of this expression has type 'bool' and is implicitly ignored. Consider using 'ignore' to discard this value explicitly, e.g. 'expr |> ignore', or 'let' to bind the result to a name, e.g. 'let result = expr'." |] - [] + [] let ``Runtime Type Test In Pattern``() = CompilerAssert.TypeCheckWithErrors """ @@ -91,7 +90,7 @@ let c = FSharpErrorSeverity.Error, 193, (8, 5, 8, 28), "Type constraint mismatch. The type \n 'IDictionary' \nis not compatible with type\n 'Dictionary' \n" |] - [] + [] let ``Runtime Type Test In Pattern 2``() = CompilerAssert.TypeCheckWithErrors """ @@ -109,7 +108,7 @@ let c = FSharpErrorSeverity.Error, 193, (8, 5, 8, 28), "Type constraint mismatch. The type \n 'IDictionary' \nis not compatible with type\n 'Dictionary' \n" |] - [] + [] let ``Override Errors``() = CompilerAssert.TypeCheckWithErrors """ @@ -130,7 +129,7 @@ type Derived3() = override x.Member (s : string, i : int) = sprintf "Hello %s" s """ [| - FSharpErrorSeverity.Error, 856, (8, 16, 8, 22), "This override takes a different number of arguments to the corresponding abstract member. The following abstract members were found:\r\n abstract member Base.Member : int * string -> string" - FSharpErrorSeverity.Error, 856, (12, 16, 12, 22), "This override takes a different number of arguments to the corresponding abstract member. The following abstract members were found:\r\n abstract member Base.Member : int * string -> string" + FSharpErrorSeverity.Error, 856, (8, 16, 8, 22), "This override takes a different number of arguments to the corresponding abstract member. The following abstract members were found:" + System.Environment.NewLine + " abstract member Base.Member : int * string -> string" + FSharpErrorSeverity.Error, 856, (12, 16, 12, 22), "This override takes a different number of arguments to the corresponding abstract member. The following abstract members were found:" + System.Environment.NewLine + " abstract member Base.Member : int * string -> string" FSharpErrorSeverity.Error, 1, (16, 24, 16, 34), "This expression was expected to have type\n 'int' \nbut here has type\n 'string' " |] diff --git a/tests/fsharp/Compiler/ErrorMessages/UnitGenericAbstactType.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnitGenericAbstactType.fs similarity index 91% rename from tests/fsharp/Compiler/ErrorMessages/UnitGenericAbstactType.fs rename to tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnitGenericAbstactType.fs index 3fee1050ef9..11ec30ab19a 100644 --- a/tests/fsharp/Compiler/ErrorMessages/UnitGenericAbstactType.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnitGenericAbstactType.fs @@ -1,15 +1,15 @@ // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. -namespace FSharp.Compiler.UnitTests +namespace FSharp.Compiler.ErrorMessages.ComponentTests -open NUnit.Framework +open Xunit open FSharp.Test.Utilities open FSharp.Compiler.SourceCodeServices -[] + module ``Unit generic abstract Type`` = - [] + [] let ``Unit can not be used as return type of abstract method paramete on return type``() = CompilerAssert.TypeCheckSingleError """ diff --git a/tests/fsharp/Compiler/ErrorMessages/UpcastDowncastTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UpcastDowncastTests.fs similarity index 94% rename from tests/fsharp/Compiler/ErrorMessages/UpcastDowncastTests.fs rename to tests/FSharp.Compiler.ComponentTests/ErrorMessages/UpcastDowncastTests.fs index 384164bff22..79e32f9e3e0 100644 --- a/tests/fsharp/Compiler/ErrorMessages/UpcastDowncastTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UpcastDowncastTests.fs @@ -1,15 +1,14 @@ // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. -namespace FSharp.Compiler.UnitTests +namespace FSharp.Compiler.ErrorMessages.ComponentTests -open NUnit.Framework +open Xunit open FSharp.Test.Utilities open FSharp.Compiler.SourceCodeServices -[] module ``Upcast and Downcast`` = - [] + [] let ``Downcast Instead Of Upcast``() = CompilerAssert.TypeCheckSingleError """ @@ -23,7 +22,7 @@ let c = orig :> Dictionary (5, 9, 5, 36) "Type constraint mismatch. The type \n 'IDictionary' \nis not compatible with type\n 'Dictionary' \n" - [] + [] let ``Upcast Instead Of Downcast``() = CompilerAssert.TypeCheckWithErrors """ @@ -37,7 +36,7 @@ let c = orig :?> IDictionary FSharpErrorSeverity.Error, 3198, (5, 9, 5, 38), "The conversion from Dictionary to IDictionary is a compile-time safe upcast, not a downcast. Consider using the :> (upcast) operator instead of the :?> (downcast) operator." |] - [] + [] let ``Upcast Function Instead Of Downcast``() = CompilerAssert.TypeCheckWithErrors """ diff --git a/tests/fsharp/Compiler/ErrorMessages/WarnExpressionTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/WarnExpressionTests.fs similarity index 97% rename from tests/fsharp/Compiler/ErrorMessages/WarnExpressionTests.fs rename to tests/FSharp.Compiler.ComponentTests/ErrorMessages/WarnExpressionTests.fs index 1df40553ce7..565e423407b 100644 --- a/tests/fsharp/Compiler/ErrorMessages/WarnExpressionTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/WarnExpressionTests.fs @@ -1,15 +1,15 @@ // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. -namespace FSharp.Compiler.UnitTests +namespace FSharp.Compiler.ErrorMessages.ComponentTests -open NUnit.Framework +open Xunit open FSharp.Test.Utilities open FSharp.Compiler.SourceCodeServices -[] + module ``Warn Expression`` = - [] + [] let ``Warn If Expression Result Unused``() = CompilerAssert.TypeCheckSingleError """ @@ -21,7 +21,7 @@ printfn "%d" 3 (2, 1, 2, 6) "The result of this expression has type 'int' and is implicitly ignored. Consider using 'ignore' to discard this value explicitly, e.g. 'expr |> ignore', or 'let' to bind the result to a name, e.g. 'let result = expr'." - [] + [] let ``Warn If Possible Assignment``() = CompilerAssert.TypeCheckSingleError """ @@ -37,7 +37,7 @@ let changeX() = (6, 5, 6, 11) "The result of this equality expression has type 'bool' and is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'. If you intended to mutate a value, then mark the value 'mutable' and use the '<-' operator e.g. 'x <- expression'." - [] + [] let ``Warn If Possible Assignment To Mutable``() = CompilerAssert.TypeCheckSingleError """ @@ -53,7 +53,7 @@ let changeX() = (6, 5, 6, 11) "The result of this equality expression has type 'bool' and is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'. If you intended to mutate a value, then use the '<-' operator e.g. 'x <- expression'." - [] + [] let ``Warn If Possible dotnet Property Setter``() = CompilerAssert.TypeCheckWithErrors """ @@ -71,7 +71,7 @@ let changeProperty() = FSharpErrorSeverity.Warning, 20, (8, 5, 8, 21), "The result of this equality expression has type 'bool' and is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'. If you intended to set a value to a property, then use the '<-' operator e.g. 'z.Enabled <- expression'." |] - [] + [] let ``Don't Warn If Property Without Setter``() = CompilerAssert.TypeCheckSingleError """ @@ -90,7 +90,7 @@ let changeProperty() = (9, 5, 9, 23) "The result of this equality expression has type 'bool' and is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'." - [] + [] let ``Warn If Implicitly Discarded``() = CompilerAssert.TypeCheckSingleError """ @@ -106,7 +106,7 @@ let changeX() = (6, 5, 6, 15) "The result of this equality expression has type 'bool' and is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'." - [] + [] let ``Warn If Discarded In List``() = CompilerAssert.TypeCheckWithErrorsAndOptions [| "--langversion:4.6" |] @@ -128,7 +128,7 @@ let view model dispatch = "This expression returns a value of type 'int' but is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'. If you intended to use the expression as a value in the sequence then use an explicit 'yield'." |] - [] + [] let ``Warn If Discarded In List 2``() = CompilerAssert.TypeCheckWithErrorsAndOptions [| "--langversion:4.6" |] @@ -155,7 +155,7 @@ let view model dispatch = "This expression returns a value of type 'int list' but is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'. If you intended to use the expression as a value in the sequence then use an explicit 'yield!'." |] - [] + [] let ``Warn If Discarded In List 3``() = CompilerAssert.TypeCheckWithErrorsAndOptions [| "--langversion:4.6" |] @@ -182,7 +182,7 @@ let view model dispatch = "The result of this expression has type 'bool' and is implicitly ignored. Consider using 'ignore' to discard this value explicitly, e.g. 'expr |> ignore', or 'let' to bind the result to a name, e.g. 'let result = expr'." |] - [] + [] let ``Warn Only On Last Expression``() = CompilerAssert.TypeCheckSingleError """ @@ -197,7 +197,7 @@ while x < 1 do (6, 5, 6, 9) "The result of this expression has type 'bool' and is implicitly ignored. Consider using 'ignore' to discard this value explicitly, e.g. 'expr |> ignore', or 'let' to bind the result to a name, e.g. 'let result = expr'." - [] + [] let ``Warn If Possible Property Setter``() = CompilerAssert.TypeCheckSingleError """ @@ -218,7 +218,7 @@ let changeProperty() = "The result of this equality expression has type 'bool' and is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'. If you intended to set a value to a property, then use the '<-' operator e.g. 'x.Property2 <- expression'." - [] + [] let ``Dont warn external function as unused``() = CompilerAssert.Pass """ diff --git a/tests/fsharp/Compiler/ErrorMessages/WrongSyntaxInForLoop.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/WrongSyntaxInForLoop.fs similarity index 86% rename from tests/fsharp/Compiler/ErrorMessages/WrongSyntaxInForLoop.fs rename to tests/FSharp.Compiler.ComponentTests/ErrorMessages/WrongSyntaxInForLoop.fs index 9747bbfa6aa..d7cd6068103 100644 --- a/tests/fsharp/Compiler/ErrorMessages/WrongSyntaxInForLoop.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/WrongSyntaxInForLoop.fs @@ -1,15 +1,15 @@ // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. -namespace FSharp.Compiler.UnitTests +namespace FSharp.Compiler.ErrorMessages.ComponentTests -open NUnit.Framework +open Xunit open FSharp.Test.Utilities open FSharp.Compiler.SourceCodeServices -[] + module ``Wrong syntax in for loop`` = - [] + [] let ``Equals instead of in``() = CompilerAssert.ParseWithErrors """ diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index 6f9172bf9bc..e78ad8e7725 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -4,7 +4,10 @@ net472;netcoreapp3.1 + win-x86;win-x64;linux-x64;osx-x64 netcoreapp3.1 + linux-x64;osx-x64 + $(AssetTargetFallback);portable-net45+win8+wp8+wpa81 true Library true @@ -16,7 +19,24 @@ - + + + + + + + + + + + + + + + + + + diff --git a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/StringModule.fs b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/StringModule.fs index a72ab64e236..6c1b1360585 100644 --- a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/StringModule.fs +++ b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/StringModule.fs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. namespace FSharp.Core.UnitTests.Collections @@ -71,11 +71,35 @@ type StringModule() = [] member this.Map() = - let e1 = String.map (fun c -> c) "foo" - Assert.AreEqual("foo", e1) + let e1 = String.map id "xyz" + Assert.AreEqual("xyz", e1) - let e2 = String.map (fun c -> c) null - Assert.AreEqual("", e2) + let e2 = String.map (fun c -> c + char 1) "abcde" + Assert.AreEqual("bcdef", e2) + + let e3 = String.map (fun c -> c) null + Assert.AreEqual("", e3) + + let e4 = String.map (fun c -> c) String.Empty + Assert.AreEqual("", e4) + + let e5 = String.map (fun _ -> 'B') "A" + Assert.AreEqual("B", e5) + + let e6 = String.map (fun _ -> failwith "should not raise") null + Assert.AreEqual("", e6) + + // this tests makes sure mapping function is not called too many times + let mutable x = 0 + let e7 = String.map (fun _ -> if x > 2 then failwith "should not raise" else x <- x + 1; 'x') "abc" + Assert.AreEqual(x, 3) + Assert.AreEqual(e7, "xxx") + + // side-effect and "order of operation" test + let mutable x = 0 + let e8 = String.map (fun c -> x <- x + 1; c + char x) "abcde" + Assert.AreEqual(x, 5) + Assert.AreEqual(e8, "bdfhj") [] member this.MapI() = @@ -87,18 +111,25 @@ type StringModule() = [] member this.Filter() = - let e1 = String.filter (fun c -> true) "foo" - Assert.AreEqual("foo", e1) + let e1 = String.filter (fun c -> true) "Taradiddle" + Assert.AreEqual("Taradiddle", e1) let e2 = String.filter (fun c -> true) null Assert.AreEqual("", e2) - let e3 = String.filter (fun c -> c <> 'o') "foo bar" - Assert.AreEqual("f bar", e3) + let e3 = String.filter Char.IsUpper "How Vexingly Quick Daft Zebras Jump!" + Assert.AreEqual("HVQDZJ", e3) let e4 = String.filter (fun c -> c <> 'o') "" Assert.AreEqual("", e4) + let e5 = String.filter (fun c -> c > 'B' ) "ABRACADABRA" + Assert.AreEqual("RCDR", e5) + + // LOH test with 55k string, which is 110k bytes + let e5 = String.filter (fun c -> c > 'B' ) (String.replicate 5_000 "ABRACADABRA") + Assert.AreEqual(String.replicate 5_000 "RCDR", e5) + [] member this.Collect() = let e1 = String.collect (fun c -> "a"+string c) "foo" @@ -125,15 +156,42 @@ type StringModule() = [] member this.Replicate() = - let e1 = String.replicate 0 "foo" + let e1 = String.replicate 0 "Snickersnee" Assert.AreEqual("", e1) - let e2 = String.replicate 2 "foo" - Assert.AreEqual("foofoo", e2) + let e2 = String.replicate 2 "Collywobbles, " + Assert.AreEqual("Collywobbles, Collywobbles, ", e2) let e3 = String.replicate 2 null Assert.AreEqual("", e3) + let e4 = String.replicate 300_000 "" + Assert.AreEqual("", e4) + + let e5 = String.replicate 23 "天地玄黃,宇宙洪荒。" + Assert.AreEqual(230 , e5.Length) + Assert.AreEqual("天地玄黃,宇宙洪荒。天地玄黃,宇宙洪荒。", e5.Substring(0, 20)) + + // This tests the cut-off point for the O(log(n)) algorithm with a prime number + let e6 = String.replicate 84673 "!!!" + Assert.AreEqual(84673 * 3, e6.Length) + + // This tests the cut-off point for the O(log(n)) algorithm with a 2^x number + let e7 = String.replicate 1024 "!!!" + Assert.AreEqual(1024 * 3, e7.Length) + + let e8 = String.replicate 1 "What a wonderful world" + Assert.AreEqual("What a wonderful world", e8) + + let e9 = String.replicate 3 "أضعت طريقي! أضعت طريقي" // means: I'm lost + Assert.AreEqual("أضعت طريقي! أضعت طريقيأضعت طريقي! أضعت طريقيأضعت طريقي! أضعت طريقي", e9) + + let e10 = String.replicate 4 "㏖ ㏗ ℵ " + Assert.AreEqual("㏖ ㏗ ℵ ㏖ ㏗ ℵ ㏖ ㏗ ℵ ㏖ ㏗ ℵ ", e10) + + let e11 = String.replicate 5 "5" + Assert.AreEqual("55555", e11) + CheckThrowsArgumentException(fun () -> String.replicate -1 "foo" |> ignore) [] diff --git a/tests/FSharp.Test.Utilities/CompilerAssert.fs b/tests/FSharp.Test.Utilities/CompilerAssert.fs index 42296116616..ac75e88ee9a 100644 --- a/tests/FSharp.Test.Utilities/CompilerAssert.fs +++ b/tests/FSharp.Test.Utilities/CompilerAssert.fs @@ -283,7 +283,11 @@ let main argv = 0""" | CompilationReference (cmpl, staticLink) -> compileCompilationAux outputPath disposals ignoreWarnings cmpl, staticLink | TestCompilationReference (cmpl) -> - let tmp = Path.Combine(outputPath, Path.ChangeExtension(Path.GetRandomFileName(), ".dll")) + let filename = + match cmpl with + | TestCompilation.CSharp c -> c.AssemblyName + | _ -> Path.GetRandomFileName() + let tmp = Path.Combine(outputPath, Path.ChangeExtension(filename, ".dll")) disposals.Add({ new IDisposable with member _.Dispose() = try File.Delete tmp with | _ -> () }) diff --git a/tests/FSharp.Test.Utilities/FSharp.Test.Utilities.fsproj b/tests/FSharp.Test.Utilities/FSharp.Test.Utilities.fsproj index 8553d2cfd44..5ddfa74eb83 100644 --- a/tests/FSharp.Test.Utilities/FSharp.Test.Utilities.fsproj +++ b/tests/FSharp.Test.Utilities/FSharp.Test.Utilities.fsproj @@ -25,8 +25,12 @@ - + + + + diff --git a/tests/FSharp.Test.Utilities/TestFramework.fs b/tests/FSharp.Test.Utilities/TestFramework.fs index 6cfa0bf3022..7650ee38168 100644 --- a/tests/FSharp.Test.Utilities/TestFramework.fs +++ b/tests/FSharp.Test.Utilities/TestFramework.fs @@ -96,6 +96,9 @@ module Commands = let csc exec cscExe flags srcFiles = exec cscExe (sprintf "%s %s" flags (srcFiles |> Seq.ofList |> String.concat " ")) + let vbc exec vbcExe flags srcFiles = + exec vbcExe (sprintf "%s %s" flags (srcFiles |> Seq.ofList |> String.concat " ")) + let fsi exec fsiExe flags sources = exec fsiExe (sprintf "%s %s" flags (sources |> Seq.ofList |> String.concat " ")) @@ -123,6 +126,8 @@ type TestConfig = { EnvironmentVariables : Map CSC : string csc_flags : string + VBC : string + vbc_flags : string BUILD_CONFIG : string FSC : string fsc_flags : string @@ -213,7 +218,8 @@ let config configurationName envVars = let artifactsPath = repoRoot ++ "artifacts" let artifactsBinPath = artifactsPath ++ "bin" let coreClrRuntimePackageVersion = "3.0.0-preview-27318-01" - let csc_flags = "/nologo" + let csc_flags = "/nologo" + let vbc_flags = "/nologo" let fsc_flags = "-r:System.Core.dll --nowarn:20 --define:COMPILED" let fsi_flags = "-r:System.Core.dll --nowarn:20 --define:INTERACTIVE --maxerrors:1 --abortonerror" let operatingSystem = getOperatingSystem () @@ -223,6 +229,7 @@ let config configurationName envVars = let requirePackage = requireFile packagesDir let requireArtifact = requireFile artifactsBinPath let CSC = requirePackage ("Microsoft.Net.Compilers" ++ "2.7.0" ++ "tools" ++ "csc.exe") + let VBC = requirePackage ("Microsoft.Net.Compilers" ++ "2.7.0" ++ "tools" ++ "vbc.exe") let ILDASM_EXE = if operatingSystem = "win" then "ildasm.exe" else "ildasm" let ILDASM = requirePackage (("runtime." + operatingSystem + "-" + architectureMoniker + ".Microsoft.NETCore.ILDAsm") ++ coreClrRuntimePackageVersion ++ "runtimes" ++ (operatingSystem + "-" + architectureMoniker) ++ "native" ++ ILDASM_EXE) let ILASM_EXE = if operatingSystem = "win" then "ilasm.exe" else "ilasm" @@ -231,6 +238,7 @@ let config configurationName envVars = let coreclrdll = requirePackage (("runtime." + operatingSystem + "-" + architectureMoniker + ".Microsoft.NETCore.Runtime.CoreCLR") ++ coreClrRuntimePackageVersion ++ "runtimes" ++ (operatingSystem + "-" + architectureMoniker) ++ "native" ++ CORECLR_DLL) let PEVERIFY_EXE = if operatingSystem = "win" then "PEVerify.exe" else "PEVerify" let PEVERIFY = requireArtifact ("PEVerify" ++ configurationName ++ peverifyArchitecture ++ PEVERIFY_EXE) +// let FSI_FOR_SCRIPTS = artifactsBinPath ++ "fsi" ++ configurationName ++ fsiArchitecture ++ "fsi.exe" let FSharpBuild = requireArtifact ("FSharp.Build" ++ configurationName ++ fsharpBuildArchitecture ++ "FSharp.Build.dll") let FSharpCompilerInteractiveSettings = requireArtifact ("FSharp.Compiler.Interactive.Settings" ++ configurationName ++ fsharpCompilerInteractiveSettingsArchitecture ++ "FSharp.Compiler.Interactive.Settings.dll") @@ -266,7 +274,8 @@ let config configurationName envVars = ILDASM = ILDASM ILASM = ILASM PEVERIFY = PEVERIFY - CSC = CSC + VBC = VBC + CSC = CSC BUILD_CONFIG = configurationName FSC = FSC FSI = FSI @@ -277,9 +286,10 @@ let config configurationName envVars = FSharpBuild = FSharpBuild FSharpCompilerInteractiveSettings = FSharpCompilerInteractiveSettings csc_flags = csc_flags - fsc_flags = fsc_flags + fsc_flags = fsc_flags fsi_flags = fsi_flags - Directory="" + vbc_flags = vbc_flags + Directory="" DotNetExe = dotNetExe DefaultPlatform = defaultPlatform } @@ -506,6 +516,7 @@ let fscBothToOut cfg out arg = Printf.ksprintf (Commands.fsc cfg.Directory (exec let fscBothToOutExpectFail cfg out arg = Printf.ksprintf (Commands.fsc cfg.Directory (execBothToOutExpectFail cfg cfg.Directory out) cfg.DotNetExe cfg.FSC) arg let fscAppendErrExpectFail cfg errPath arg = Printf.ksprintf (Commands.fsc cfg.Directory (execAppendErrExpectFail cfg errPath) cfg.DotNetExe cfg.FSC) arg let csc cfg arg = Printf.ksprintf (Commands.csc (exec cfg) cfg.CSC) arg +let vbc cfg arg = Printf.ksprintf (Commands.vbc (exec cfg) cfg.VBC) arg let ildasm cfg arg = Printf.ksprintf (Commands.ildasm (exec cfg) cfg.ILDASM) arg let ilasm cfg arg = Printf.ksprintf (Commands.ilasm (exec cfg) cfg.ILASM) arg let peverify cfg = Commands.peverify (exec cfg) cfg.PEVERIFY "/nologo" diff --git a/tests/FSharp.Test.Utilities/Utilities.fs b/tests/FSharp.Test.Utilities/Utilities.fs index f55d1936b5c..1415fee273f 100644 --- a/tests/FSharp.Test.Utilities/Utilities.fs +++ b/tests/FSharp.Test.Utilities/Utilities.fs @@ -60,6 +60,8 @@ module Utilities = | None = 0x0 | InternalsVisibleTo = 0x1 + // TODO: this and Compilation.Compile needs to be merged for sake of consistency. + // TODO: After merging, add new type of FSharp compilation. [] type TestCompilation = | CSharp of CSharpCompilation @@ -96,18 +98,19 @@ module Utilities = [] type CompilationUtil private () = - static member CreateCSharpCompilation (source: string, lv: CSharpLanguageVersion, ?tf, ?additionalReferences) = + static member CreateCSharpCompilation (source: string, lv: CSharpLanguageVersion, ?tf, ?additionalReferences, ?name) = let lv = match lv with | CSharpLanguageVersion.CSharp8 -> LanguageVersion.CSharp8 | _ -> LanguageVersion.Default let tf = defaultArg tf TargetFramework.NetStandard20 + let n = defaultArg name (Guid.NewGuid().ToString ()) let additionalReferences = defaultArg additionalReferences ImmutableArray.Empty let references = TargetFrameworkUtil.getReferences tf let c = CSharpCompilation.Create( - Guid.NewGuid().ToString (), + n, [ CSharpSyntaxTree.ParseText (source, CSharpParseOptions lv) ], references.As().AddRange additionalReferences, CSharpCompilationOptions (OutputKind.DynamicallyLinkedLibrary)) diff --git a/tests/fsharp/Compiler/Conformance/BasicGrammarElements/BasicConstants.fs b/tests/fsharp/Compiler/Conformance/BasicGrammarElements/BasicConstants.fs index 912fb29091f..68dda297ece 100644 --- a/tests/fsharp/Compiler/Conformance/BasicGrammarElements/BasicConstants.fs +++ b/tests/fsharp/Compiler/Conformance/BasicGrammarElements/BasicConstants.fs @@ -177,7 +177,7 @@ printfn "%A" x14 """ [] let ``dotless float``() = - CompilerAssert.CompileExeWithOptions [|"--langversion:preview"|] + CompilerAssert.CompileExeWithOptions [|"--langversion:5.0"|] """ let x = 42f printfn "%A" x @@ -193,7 +193,7 @@ printfn "%A" x [] let ``dotted floats should be equal to dotless floats``() = - CompilerAssert.CompileExeAndRunWithOptions [|"--langversion:preview"|] + CompilerAssert.CompileExeAndRunWithOptions [|"--langversion:5.0"|] """ if 1.0f <> 1f then failwith "1.0f <> 1f" """ @@ -214,14 +214,14 @@ if 1e1f <> 10.f then failwith "1e1f <> 10.f" [] let ``exponent dotted floats should be equal to dotless floats``() = - CompilerAssert.CompileExeAndRunWithOptions [|"--langversion:preview"|] + CompilerAssert.CompileExeAndRunWithOptions [|"--langversion:5.0"|] """ if 1.0e1f <> 10f then failwith "1.0e1f <> 10f" """ [] let ``exponent dotless floats should be equal to dotless floats``() = - CompilerAssert.CompileExeAndRunWithOptions [|"--langversion:preview"|] + CompilerAssert.CompileExeAndRunWithOptions [|"--langversion:5.0"|] """ if 1e1f <> 10f then failwith "1e1f <> 10f" """ diff --git a/tests/fsharp/Compiler/Conformance/Properties/ILMemberAccessTests.fs b/tests/fsharp/Compiler/Conformance/Properties/ILMemberAccessTests.fs new file mode 100644 index 00000000000..e421db9e534 --- /dev/null +++ b/tests/fsharp/Compiler/Conformance/Properties/ILMemberAccessTests.fs @@ -0,0 +1,224 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace FSharp.Compiler.UnitTests + +open FSharp.Compiler.SourceCodeServices +open FSharp.Reflection +open FSharp.Test +open FSharp.Test.Utilities +open FSharp.Test.Utilities.Utilities +open NUnit.Framework + +[] +module ILMemberAccessTests = + + let csharpBaseClass = """ +namespace ExhaustiveCombinations +{ + public class CSharpBaseClass + { + public string GetPublicSetInternal { get; internal set; } + public string GetPublicSetProtected { get; protected set; } + public string GetPublicSetPrivateProtected { get; private protected set; } + public string GetPublicSetProtectedInternal { get; protected internal set; } + public string GetPublicSetPrivate { get; private set; } + + public string SetPublicGetInternal { internal get; set; } + public string SetPublicGetProtected { protected get; set; } + public string SetPublicGetPrivateProtected { private protected get; set; } + public string SetPublicGetProtectedInternal { protected internal get; set; } + public string SetPublicGetPrivate { private get; set; } + } +} +""" + + let fsharpBaseClass = """ +namespace ExhaustiveCombinations + +open System + +type FSharpBaseClass () = + + member this.GetPublicSetInternal with public get() = "" and internal set (parameter:string) = ignore parameter + member this.GetPublicSetPrivate with public get() = "" and private set (parameter:string) = ignore parameter + member this.SetPublicGetInternal with internal get() = "" and public set (parameter:string) = ignore parameter + member this.SetPublicGetPrivate with private get() = "" and public set (parameter:string) = ignore parameter + +""" + + + [] + let ``VerifyVisibility of Properties C# class F# derived class -- AccessPublicStuff`` () = + + let fsharpSource = + fsharpBaseClass + """ +open System +open ExhaustiveCombinations + +type MyFSharpClass () = + inherit CSharpBaseClass() + + member this.AccessPublicStuff() = + + this.GetPublicSetInternal <- "1" // Inaccessible + let _ = this.GetPublicSetInternal // Accessible + + this.GetPublicSetPrivateProtected <- "1" // Accessible + let _ = this.GetPublicSetPrivateProtected // Accessible + + this.GetPublicSetProtectedInternal <- "1" // Accessible + let _ = this.GetPublicSetProtectedInternal // Accessible + + this.GetPublicSetProtected <- "1" // Accessible + let _ = this.GetPublicSetProtected // Accessible + + this.GetPublicSetPrivate <- "1" // Inaccessible + let _ = this.GetPublicSetPrivate // Accessible + () +""" + + let csCmpl = + CompilationUtil.CreateCSharpCompilation(csharpBaseClass, CSharpLanguageVersion.CSharp8, TargetFramework.NetCoreApp30) + |> CompilationReference.Create + + let fsCmpl = + Compilation.Create(fsharpSource, Fsx, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + + CompilerAssert.CompileWithErrors(fsCmpl, [| + (FSharpErrorSeverity.Error, 491, (22, 9, 22, 41), + "The member or object constructor 'GetPublicSetInternal' is not accessible. Private members may only be accessed from within the declaring type. Protected members may only be accessed from an extending type and cannot be accessed from inner lambda expressions."); + (FSharpErrorSeverity.Error, 491, (25, 9, 25, 49), + "The member or object constructor 'GetPublicSetPrivateProtected' is not accessible. Private members may only be accessed from within the declaring type. Protected members may only be accessed from an extending type and cannot be accessed from inner lambda expressions."); + (FSharpErrorSeverity.Error, 491, (34, 9, 34, 40), + "The member or object constructor 'GetPublicSetPrivate' is not accessible. Private members may only be accessed from within the declaring type. Protected members may only be accessed from an extending type and cannot be accessed from inner lambda expressions.")|]) + + + [] + let ``VerifyVisibility of Properties C# class F# non-derived class -- AccessPublicStuff`` () = + + let fsharpSource = + fsharpBaseClass + """ +open System +open ExhaustiveCombinations + +type MyFSharpClass () = + + member _.AccessPublicStuff() = + let bc = new CSharpBaseClass() + + bc.GetPublicSetInternal <- "1" // Inaccessible + let _ = bc.GetPublicSetInternal // Accessible + + bc.GetPublicSetPrivateProtected <- "1" // Inaccessible + let _ = bc.GetPublicSetPrivateProtected // Accessible + + bc.GetPublicSetProtectedInternal <- "1" // Accessible + let _ = bc.GetPublicSetProtectedInternal // Inaccessible + + bc.GetPublicSetProtected <- "1" // Inaccessible + let _ = bc.SetPublicGetProtected // Accessible + + bc.GetPublicSetPrivate <- "1" // Inaccessible + let _ = bc.GetPublicSetPrivate // Accessible + () +""" + + let csCmpl = + CompilationUtil.CreateCSharpCompilation(csharpBaseClass, CSharpLanguageVersion.CSharp8, TargetFramework.NetCoreApp30) + |> CompilationReference.Create + + let fsCmpl = + Compilation.Create(fsharpSource, Fsx, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + + CompilerAssert.CompileWithErrors(fsCmpl, [| + (FSharpErrorSeverity.Error, 491, (22, 9, 22, 39), + "The member or object constructor 'GetPublicSetInternal' is not accessible. Private members may only be accessed from within the declaring type. Protected members may only be accessed from an extending type and cannot be accessed from inner lambda expressions."); + (FSharpErrorSeverity.Error, 491, (25, 9, 25, 47), + "The member or object constructor 'GetPublicSetPrivateProtected' is not accessible. Private members may only be accessed from within the declaring type. Protected members may only be accessed from an extending type and cannot be accessed from inner lambda expressions."); + (FSharpErrorSeverity.Error, 491, (28, 9, 28, 48), + "The member or object constructor 'GetPublicSetProtectedInternal' is not accessible. Private members may only be accessed from within the declaring type. Protected members may only be accessed from an extending type and cannot be accessed from inner lambda expressions."); + (FSharpErrorSeverity.Error, 491, (31, 9, 31, 40), + "The member or object constructor 'GetPublicSetProtected' is not accessible. Private members may only be accessed from within the declaring type. Protected members may only be accessed from an extending type and cannot be accessed from inner lambda expressions."); + (FSharpErrorSeverity.Error, 491, (32, 17, 32, 41), + "The member or object constructor 'SetPublicGetProtected' is not accessible. Private members may only be accessed from within the declaring type. Protected members may only be accessed from an extending type and cannot be accessed from inner lambda expressions."); + (FSharpErrorSeverity.Error, 491, (34, 9, 34, 38), + "The member or object constructor 'GetPublicSetPrivate' is not accessible. Private members may only be accessed from within the declaring type. Protected members may only be accessed from an extending type and cannot be accessed from inner lambda expressions.")|]) + + + [] + let ``VerifyVisibility of Properties F# base F# derived class -- AccessPublicStuff`` () = + + let fsharpSource = + fsharpBaseClass + """ +open System +open ExhaustiveCombinations + +type MyFSharpClass () = + inherit FSharpBaseClass() + + member this.AccessPublicStuff() = + + this.GetPublicSetInternal <- "1" // Inaccessible + let _ = this.GetPublicSetInternal // Accessible + + this.GetPublicSetPrivate <- "1" // Inaccessible + let _ = this.GetPublicSetPrivate // Accessible + + this.SetPublicGetInternal <- "1" // Accessible + let _ = this.SetPublicGetInternal // Inaccessible + + this.SetPublicGetPrivate <- "1" // Accessible + let _ = this.SetPublicGetPrivate // accessible + + () +""" + + let csCmpl = + CompilationUtil.CreateCSharpCompilation(csharpBaseClass, CSharpLanguageVersion.CSharp8, TargetFramework.NetCoreApp30) + |> CompilationReference.Create + + let fsCmpl = + Compilation.Create(fsharpSource, Fsx, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + + CompilerAssert.CompileWithErrors(fsCmpl, [| + (FSharpErrorSeverity.Error, 810, (25, 9, 25, 33), + "Property 'GetPublicSetPrivate' cannot be set"); + (FSharpErrorSeverity.Error, 807, (32, 17, 32, 41), + "Property 'SetPublicGetPrivate' is not readable") + |]) + + + [] + let ``VerifyVisibility of Properties F# class F# non-derived class -- AccessPublicStuff`` () = + + let fsharpSource = + fsharpBaseClass + """ +open System +open ExhaustiveCombinations + +type MyFSharpClass () = + + member _.AccessPublicStuff() = + let bc = new FSharpBaseClass() + + bc.GetPublicSetInternal <- "1" // Inaccessible + let _ = bc.GetPublicSetInternal // Accessible + + bc.GetPublicSetPrivate <- "1" // Inaccessible + let _ = bc.GetPublicSetPrivate // Accessible + () +""" + + let csCmpl = + CompilationUtil.CreateCSharpCompilation(csharpBaseClass, CSharpLanguageVersion.CSharp8, TargetFramework.NetCoreApp30) + |> CompilationReference.Create + + let fsCmpl = + Compilation.Create(fsharpSource, Fsx, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + + CompilerAssert.CompileWithErrors(fsCmpl, [| + (FSharpErrorSeverity.Error, 810, (25, 9, 25, 31), + "Property 'GetPublicSetPrivate' cannot be set")|]) + + + diff --git a/tests/fsharp/Compiler/ErrorMessages/AccessOfTypeAbbreviationTests.fs b/tests/fsharp/Compiler/ErrorMessages/AccessOfTypeAbbreviationTests.fs deleted file mode 100644 index f6fc14bbef5..00000000000 --- a/tests/fsharp/Compiler/ErrorMessages/AccessOfTypeAbbreviationTests.fs +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. - -namespace FSharp.Compiler.UnitTests - -open NUnit.Framework -open FSharp.Test.Utilities -open FSharp.Compiler.SourceCodeServices - -[] -module ``Access Of Type Abbreviation`` = - - [] - let ``Test1``() = - CompilerAssert.TypeCheckSingleError - """ -module Library = - type private Hidden = Hidden of unit - type Exported = Hidden - """ - FSharpErrorSeverity.Warning - 44 - (4, 8, 4, 16) - "This construct is deprecated. The type 'Hidden' is less accessible than the value, member or type 'Exported' it is used in.\r\nAs of F# 4.1, the accessibility of type abbreviations is checked at compile-time. Consider changing the accessibility of the type abbreviation. Ignoring this warning might lead to runtime errors." - - [] - let ``Test2``() = - CompilerAssert.Pass - """ -module Library = - type internal Hidden = Hidden of unit - type internal Exported = Hidden - """ - - [] - let ``Test3``() = - CompilerAssert.TypeCheckSingleError - """ -module Library = - type internal Hidden = Hidden of unit - type Exported = Hidden - """ - FSharpErrorSeverity.Warning - 44 - (4, 8, 4, 16) - "This construct is deprecated. The type 'Hidden' is less accessible than the value, member or type 'Exported' it is used in.\r\nAs of F# 4.1, the accessibility of type abbreviations is checked at compile-time. Consider changing the accessibility of the type abbreviation. Ignoring this warning might lead to runtime errors." - - [] - let ``Test4``() = - CompilerAssert.TypeCheckSingleError - """ -module Library = - type private Hidden = Hidden of unit - type internal Exported = Hidden - """ - FSharpErrorSeverity.Warning - 44 - (4, 17, 4, 25) - "This construct is deprecated. The type 'Hidden' is less accessible than the value, member or type 'Exported' it is used in.\r\nAs of F# 4.1, the accessibility of type abbreviations is checked at compile-time. Consider changing the accessibility of the type abbreviation. Ignoring this warning might lead to runtime errors." - - [] - let ``Test5``() = - CompilerAssert.Pass - """ -module Library = - type private Hidden = Hidden of unit - type private Exported = Hidden - """ - - [] - let ``Test6``() = - CompilerAssert.Pass - """ -module Library = - type Hidden = Hidden of unit - type Exported = Hidden - """ diff --git a/tests/fsharp/Compiler/Language/DefaultInterfaceMemberTests.fs b/tests/fsharp/Compiler/Language/DefaultInterfaceMemberTests.fs index fbd968178f1..d64067ddfa9 100644 --- a/tests/fsharp/Compiler/Language/DefaultInterfaceMemberTests.fs +++ b/tests/fsharp/Compiler/Language/DefaultInterfaceMemberTests.fs @@ -11,7 +11,7 @@ open FSharp.Compiler.SourceCodeServices module private DefaultInterfaceMemberConsumptionLanguageVersion = [] - let targetVersion = "'preview'" + let targetVersion = "5.0" #if NETCOREAPP @@ -1125,7 +1125,7 @@ type Test () = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.CompileWithErrors(fsCmpl, [| (FSharpErrorSeverity.Error, 366, (8, 15, 8, 20), "No implementation was given for 'ITest.NonDefaultMethod() : unit'. Note that all interface members must be implemented and listed under an appropriate 'interface' declaration, e.g. 'interface ... with member ...'.") @@ -1175,7 +1175,7 @@ let main _ = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "I1.+1") @@ -1225,7 +1225,7 @@ let main _ = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "DefaultMethod-NonDefaultMethod") @@ -1299,7 +1299,7 @@ let main _ = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "ProtectedProtected-ProtectedOverrideProtectedOverride") @@ -1362,7 +1362,7 @@ let main _ = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "ObjExprProtectedObjExprProtected-ObjExprProtected2ObjExprProtected2") @@ -1437,7 +1437,7 @@ let f () = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.CompileWithErrors(fsCmpl, [| (FSharpErrorSeverity.Error, 491, (26, 5, 26, 15), "The member or object constructor 'M1' is not accessible. Private members may only be accessed from within the declaring type. Protected members may only be accessed from an extending type and cannot be accessed from inner lambda expressions.") @@ -1517,7 +1517,7 @@ type Test2 () = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.CompileWithErrors(fsCmpl, [| (FSharpErrorSeverity.Error, 629, (10, 9, 10, 27), "Method 'M1' is not accessible from this code location") @@ -1570,7 +1570,7 @@ let main _ = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "NonDefaultMethod") @@ -1619,7 +1619,7 @@ let f () = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.CompileWithErrors(fsCmpl, [| (FSharpErrorSeverity.Error, 39, (16, 10, 16, 23), "The type 'ITest' does not define the field, constructor or member 'DefaultMethod'. Maybe you want one of the following: @@ -1669,7 +1669,7 @@ type Test () = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.CompileWithErrors(fsCmpl, [| (FSharpErrorSeverity.Error, 855, (11, 19, 11, 32), "No abstract or interface member was found that corresponds to this override") @@ -1726,7 +1726,7 @@ let main _ = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl], name = "Test") + Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl], name = "Test") CompilerAssert.ExecutionHasOutput(fsCmpl, "IVT-NonDefaultMethod") @@ -1765,7 +1765,7 @@ let main _ = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "DefaultMethod") @@ -1808,7 +1808,7 @@ let main _ = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "DefaultMethod-ObjExpr") @@ -1847,7 +1847,7 @@ let test = { new ITest } |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.CompileWithErrors(fsCmpl, [| (FSharpErrorSeverity.Error, 366, (7, 12, 7, 25), "No implementation was given for 'ITest.NonDefaultMethod() : unit'. Note that all interface members must be implemented and listed under an appropriate 'interface' declaration, e.g. 'interface ... with member ...'.") @@ -1902,7 +1902,7 @@ let main _ = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "OverrideDefaultMethod-NonDefaultMethod") @@ -1950,7 +1950,7 @@ let main _ = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "ObjExprOverrideDefaultMethod-ObjExprNonDefaultMethod") @@ -2010,7 +2010,7 @@ let main _ = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "FromITest2-Method1-FromITest2-Method2") @@ -2078,7 +2078,7 @@ type Test () = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.CompileWithErrors(fsCmpl, [| (FSharpErrorSeverity.Error, 363, (9, 15, 9, 21), "The interface 'ITest1' is included in multiple explicitly implemented interface types. Add an explicit implementation of this interface.") @@ -2161,7 +2161,7 @@ type Test () = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.CompileWithErrors(fsCmpl, [| (FSharpErrorSeverity.Error, 3352, (9, 15, 9, 21), "Interface member 'ITest1.Method1() : unit' does not have a most specific implementation.") @@ -2239,7 +2239,7 @@ type Test () = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.CompileWithErrors(fsCmpl, [| (FSharpErrorSeverity.Error, 3352, (9, 15, 9, 28), "Interface member 'ITest1.Method1() : unit' does not have a most specific implementation.") @@ -2317,7 +2317,7 @@ type Test () = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.CompileWithErrors(fsCmpl, [| (FSharpErrorSeverity.Error, 3352, (13, 15, 13, 28), "Interface member 'ITest1.Method1() : unit' does not have a most specific implementation.") @@ -2389,7 +2389,7 @@ type Test () = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.CompileWithErrors(fsCmpl, [| (FSharpErrorSeverity.Error, 3352, (13, 15, 13, 28), "Interface member 'ITest1.Method1() : unit' does not have a most specific implementation.") @@ -2455,7 +2455,7 @@ type Test () = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.CompileWithErrors(fsCmpl, [| (FSharpErrorSeverity.Error, 3352, (13, 15, 13, 28), "Interface member 'ITest1.Method1() : unit' does not have a most specific implementation.") @@ -2544,7 +2544,7 @@ let main _ = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "FSharpICombinedTest-Method1-FSharpICombinedTest-Method2") @@ -2614,7 +2614,7 @@ let main _ = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "FSharpICombinedTest-Method1-FSharpICombinedTest-Method2") @@ -2693,7 +2693,7 @@ let main _ = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "FSharpExplicitTest-Method1-FSharpExplicitTest-Method2") @@ -2755,7 +2755,7 @@ type Test () = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.CompileWithErrors(fsCmpl, [| (FSharpErrorSeverity.Error, 3352, (14, 15, 14, 28), "Interface member 'ITest1.Method1() : unit' does not have a most specific implementation.") @@ -2844,7 +2844,7 @@ let main _ = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "CSharpICombinedTest-Method1-CSharpICombinedTest-Method2") @@ -2969,7 +2969,7 @@ let main _ = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "CSharpIFinalCombinedTest-Method1-CSharpIFinalCombinedTest-Method2") @@ -3080,7 +3080,7 @@ let main _ = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "CSharpIFinalCombinedTest-Method1-") @@ -3192,7 +3192,7 @@ let main _ = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "CSharpIFinalCombinedTest-Method1-CSharpIFinalCombinedTest-Method2") @@ -3308,7 +3308,7 @@ let main _ = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "IBase-IB1-IA1-IC1-") @@ -3414,7 +3414,7 @@ let main _ = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "123XYZ") @@ -3517,7 +3517,7 @@ let main _ = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "-") @@ -3616,7 +3616,7 @@ type Test2 () = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.CompileWithErrors(fsCmpl, [| (FSharpErrorSeverity.Error, 366, (10, 15, 10, 32), "No implementation was given for 'ITest1.Method2() : unit'. Note that all interface members must be implemented and listed under an appropriate 'interface' declaration, e.g. 'interface ... with member ...'.") @@ -3663,7 +3663,7 @@ let main _ = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "A-NonDefaultMethod") @@ -3710,7 +3710,7 @@ let main _ = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "OverrideA-NonDefaultMethod") @@ -3773,7 +3773,7 @@ let main _ = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "") @@ -3840,7 +3840,7 @@ let main _ = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "IA.MA-IB1.IB.MB-IB1.IB.MB") @@ -3888,7 +3888,7 @@ type Test () = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.CompileWithErrors(fsCmpl, [| (FSharpErrorSeverity.Error, 363, (8, 15, 8, 17), "The interface 'IA' is included in multiple explicitly implemented interface types. Add an explicit implementation of this interface.") @@ -3943,7 +3943,7 @@ type Test () = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.CompileWithErrors(fsCmpl, [| (FSharpErrorSeverity.Error, 3352, (10, 15, 10, 17), "Interface member 'IA.M() : unit' does not have a most specific implementation.") @@ -4008,7 +4008,7 @@ let main _ = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "MMM") @@ -4098,7 +4098,7 @@ let main _ = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "M123456floatfs_single") @@ -4176,7 +4176,7 @@ type Test () = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.CompileWithErrors(fsCmpl, [| (FSharpErrorSeverity.Error, 366, (12, 15, 12, 17), "No implementation was given for 'IA.M(x: float32) : unit'. Note that all interface members must be implemented and listed under an appropriate 'interface' declaration, e.g. 'interface ... with member ...'.") @@ -4273,7 +4273,7 @@ let main _ = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "InTestInTest123456789111STRING-STRINGABC222FSharpABC333CSharpM(U, T)M(U, T)") @@ -4368,7 +4368,7 @@ let main _ = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "Test.String-Test.Prop2") @@ -4455,7 +4455,7 @@ type Test () = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.CompileWithErrors(fsCmpl, [| (FSharpErrorSeverity.Error, 3352, (12, 15, 12, 25), "Interface member 'IA.set_Prop2(value: string) : unit' does not have a most specific implementation.") @@ -4505,7 +4505,7 @@ let test = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Library, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.CompileWithErrors(fsCmpl, [| (FSharpErrorSeverity.Error, 363, (8, 7, 8, 21), "The interface 'IA' is included in multiple explicitly implemented interface types. Add an explicit implementation of this interface.") @@ -4568,7 +4568,7 @@ let main _ = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "IB.IA.M") @@ -4624,7 +4624,7 @@ let main _ = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fs, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "IB.IA.M") @@ -4688,7 +4688,7 @@ f () |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fsx, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fsx, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "1011") @@ -4748,7 +4748,7 @@ f3 () |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fsx, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fsx, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.ExecutionHasOutput(fsCmpl, "359") @@ -4793,7 +4793,7 @@ let f () = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fsx, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fsx, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.CompileWithErrors(fsCmpl, [| (FSharpErrorSeverity.Error, 39, (6, 17, 6, 29), "The type 'CSharpClass' does not define the field, constructor or member 'StaticMethod'.") @@ -4843,7 +4843,7 @@ let f () = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fsx, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fsx, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.CompileWithErrors(fsCmpl, [| (FSharpErrorSeverity.Error, 39, (11, 17, 11, 29), "The type 'FSharpClass' does not define the field, constructor or member 'StaticMethod'.") @@ -4893,7 +4893,7 @@ let f () = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fsx, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fsx, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.CompileWithErrors(fsCmpl, [| (FSharpErrorSeverity.Error, 1, (9, 5, 9, 15), "The type 'CSharpClass' does not support the operator 'StaticMethod'") @@ -4946,7 +4946,7 @@ let f () = |> CompilationReference.Create let fsCmpl = - Compilation.Create(fsharpSource, Fsx, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) + Compilation.Create(fsharpSource, Fsx, Exe, options = [|"--langversion:5.0"|], cmplRefs = [csCmpl]) CompilerAssert.CompileWithErrors(fsCmpl, [| (FSharpErrorSeverity.Error, 1, (14, 5, 14, 15), "The type 'FSharpClass' does not support the operator 'StaticMethod'") diff --git a/tests/fsharp/Compiler/Language/OptionalInteropTests.fs b/tests/fsharp/Compiler/Language/OptionalInteropTests.fs index 443c4f47468..a4e4d498400 100644 --- a/tests/fsharp/Compiler/Language/OptionalInteropTests.fs +++ b/tests/fsharp/Compiler/Language/OptionalInteropTests.fs @@ -43,5 +43,5 @@ Test.M(x = Some 1) CompilationUtil.CreateCSharpCompilation(csSrc, CSharpLanguageVersion.CSharp8, TargetFramework.NetStandard20, additionalReferences = ImmutableArray.CreateRange [fsharpCoreAssembly]) |> CompilationReference.Create - let fs = Compilation.Create(fsSrc, SourceKind.Fsx, CompileOutput.Exe, options = [|"--langversion:preview"|], cmplRefs = [cs]) + let fs = Compilation.Create(fsSrc, SourceKind.Fsx, CompileOutput.Exe, options = [|"--langversion:5.0"|], cmplRefs = [cs]) CompilerAssert.Compile fs diff --git a/tests/fsharp/Compiler/Libraries/Core/Operators/AbsTests.fs b/tests/fsharp/Compiler/Libraries/Core/Operators/AbsTests.fs new file mode 100644 index 00000000000..806c93b7dba --- /dev/null +++ b/tests/fsharp/Compiler/Libraries/Core/Operators/AbsTests.fs @@ -0,0 +1,94 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace FSharp.Compiler.UnitTests + +open NUnit.Framework +open FSharp.Compiler.SourceCodeServices +open FSharp.Test.Utilities + +[] +module ``Abs Tests`` = + + [] + let ``Abs of signed integral types``() = + // Regression test for FSHARP1.0:3470 - exception on abs of native integer + + Assert.areEqual (abs -1y) 1y // signed byte + Assert.areEqual (abs -1s) 1s // int16 + Assert.areEqual (abs -1l) 1l // int32 + Assert.areEqual (abs -1n) 1n // nativeint + Assert.areEqual (abs -1L) 1L // int64 + Assert.areEqual (abs -1I) 1I // bigint + + [] + let ``Abs of byte``() = + CompilerAssert.TypeCheckSingleError + """ +abs -1uy |> ignore + """ + FSharpErrorSeverity.Error + 1 + (2, 6, 2, 9) + "The type 'byte' does not support the operator 'Abs'" + + [] + let ``Abs of uint16``() = + CompilerAssert.TypeCheckSingleError + """ +abs -1us |> ignore + """ + FSharpErrorSeverity.Error + 1 + (2, 6, 2, 9) + "The type 'uint16' does not support the operator 'Abs'" + + [] + let ``Abs of uint32``() = + CompilerAssert.TypeCheckSingleError + """ +abs -1ul |> ignore + """ + FSharpErrorSeverity.Error + 1 + (2, 6, 2, 9) + "The type 'uint32' does not support the operator 'Abs'" + + CompilerAssert.TypeCheckSingleError + """ +abs -1u |> ignore + """ + FSharpErrorSeverity.Error + 1 + (2, 6, 2, 8) + "The type 'uint32' does not support the operator 'Abs'" + + [] + let ``Abs of unativeint``() = + CompilerAssert.TypeCheckSingleError + """ +abs -1un |> ignore + """ + FSharpErrorSeverity.Error + 1 + (2, 6, 2, 9) + "The type 'unativeint' does not support the operator 'Abs'" + + [] + let ``Abs of uint64``() = + CompilerAssert.TypeCheckSingleError + """ +abs -1uL |> ignore + """ + FSharpErrorSeverity.Error + 1 + (2, 6, 2, 9) + "The type 'uint64' does not support the operator 'Abs'" + + CompilerAssert.TypeCheckSingleError + """ +abs -1UL |> ignore + """ + FSharpErrorSeverity.Error + 1 + (2, 6, 2, 9) + "The type 'uint64' does not support the operator 'Abs'" \ No newline at end of file diff --git a/tests/fsharp/Compiler/Libraries/Core/Operators/CastTests.fs b/tests/fsharp/Compiler/Libraries/Core/Operators/CastTests.fs new file mode 100644 index 00000000000..5f4d34df153 --- /dev/null +++ b/tests/fsharp/Compiler/Libraries/Core/Operators/CastTests.fs @@ -0,0 +1,19 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace FSharp.Compiler.UnitTests + +open NUnit.Framework +open FSharp.Test.Utilities +open System + +[] +module ``Cast Tests`` = + + [] + let ``Cast precedence over expression forms``() = + // Regression test for FSHARP1.0:1247 + // Precedence of type annotations :> and :?> over preceeding expression forms, e.g. if-then-else etc. + + Assert.IsInstanceOf (2 :> Object) + Assert.IsInstanceOf [(2 :> Object)] + Assert.IsInstanceOf [2 :> Object] \ No newline at end of file diff --git a/tests/fsharp/Compiler/Libraries/Core/Operators/HashTests.fs b/tests/fsharp/Compiler/Libraries/Core/Operators/HashTests.fs new file mode 100644 index 00000000000..8958cd5b8e9 --- /dev/null +++ b/tests/fsharp/Compiler/Libraries/Core/Operators/HashTests.fs @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace FSharp.Compiler.UnitTests + +open NUnit.Framework +open FSharp.Compiler.SourceCodeServices +open FSharp.Test.Utilities + +[] +module ``Hash Tests`` = + + [] + let ``Hash of function values``() = + // Regression test for FSHARP1.0:5436 + // You should not be able to hash F# function values + // Note: most positive cases already covered under fsharp\typecheck\sigs + // I'm adding this simple one since I did not see it there. + + CompilerAssert.TypeCheckSingleError + """ +hash id |> ignore + """ + FSharpErrorSeverity.Error + 1 + (2, 6, 2, 8) + "The type '('a -> 'a)' does not support the 'equality' constraint because it is a function type" + + [] + let ``Unchecked hash of function values``() = + // Regression test for FSHARP1.0:5436 + // You should not be able to hash F# function values + // Note: most positive cases already covered under fsharp\typecheck\sigs + // I'm adding this simple one since I did not see it there. + + // This is ok (unchecked) + CompilerAssert.TypeCheckWithErrors + """ +Unchecked.hash id |> ignore + """ + [||] \ No newline at end of file diff --git a/tests/fsharp/Compiler/Libraries/Core/Operators/PowTests.fs b/tests/fsharp/Compiler/Libraries/Core/Operators/PowTests.fs new file mode 100644 index 00000000000..4bdb77bca28 --- /dev/null +++ b/tests/fsharp/Compiler/Libraries/Core/Operators/PowTests.fs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace FSharp.Compiler.UnitTests + +open NUnit.Framework + +[] +module ``Pow Tests`` = + + type T() = + static let mutable m = false + static member Pow (g: T, _: float) = + m <- true + g + static member Check() = m + + [] + let ``Pow of custom type``() = + // Regression test for FSHARP1.0:4487 + // Feature request: loosen Pow operator constraints + + let t = T() + let _ = t ** 3. + + Assert.IsTrue (T.Check()) \ No newline at end of file diff --git a/tests/fsharp/Compiler/Libraries/Core/Operators/RoundTests.fs b/tests/fsharp/Compiler/Libraries/Core/Operators/RoundTests.fs new file mode 100644 index 00000000000..bdb8e321823 --- /dev/null +++ b/tests/fsharp/Compiler/Libraries/Core/Operators/RoundTests.fs @@ -0,0 +1,58 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace FSharp.Compiler.UnitTests + +open NUnit.Framework + +[] +module ``Round Tests`` = + + [] + let ``Round of integers``() = + for i in [1 .. 10000] do + Assert.areEqual (i |> float |> round) (float i) + Assert.areEqual (i |> float32 |> round) (float32 i) + Assert.areEqual (i |> decimal |> round) (decimal i) + + [] + let ``Round of floats``() = + // Round down + Assert.areEqual (round 1.1) 1.0 + Assert.areEqual (round 1.2) 1.0 + Assert.areEqual (round 1.3) 1.0 + Assert.areEqual (round 1.4) 1.0 + Assert.areEqual (round 1.1f) 1.0f + Assert.areEqual (round 1.2f) 1.0f + Assert.areEqual (round 1.3f) 1.0f + Assert.areEqual (round 1.4f) 1.0f + Assert.areEqual (round 1.1m) 1.0m + Assert.areEqual (round 1.2m) 1.0m + Assert.areEqual (round 1.3m) 1.0m + Assert.areEqual (round 1.4m) 1.0m + + // Round down + Assert.areEqual (round 1.6) 2.0 + Assert.areEqual (round 1.7) 2.0 + Assert.areEqual (round 1.8) 2.0 + Assert.areEqual (round 1.9) 2.0 + Assert.areEqual (round 1.6f) 2.0f + Assert.areEqual (round 1.7f) 2.0f + Assert.areEqual (round 1.8f) 2.0f + Assert.areEqual (round 1.9f) 2.0f + Assert.areEqual (round 1.6m) 2.0m + Assert.areEqual (round 1.7m) 2.0m + Assert.areEqual (round 1.8m) 2.0m + Assert.areEqual (round 1.9m) 2.0m + + // Midpoint rounding. If between two numbers, round to the 'even' one. + Assert.areEqual (round 1.5 ) 2.0 + Assert.areEqual (round 1.5f) 2.0f + Assert.areEqual (round 1.5m) 2.0m + Assert.areEqual (round 2.5 ) 2.0 + Assert.areEqual (round 2.5f) 2.0f + Assert.areEqual (round 2.5m) 2.0m + + // If not midpoint, round to nearest as usual + Assert.areEqual (round 2.500001 ) 3.0 + Assert.areEqual (round 2.500001f) 3.0f + Assert.areEqual (round 2.500001m) 3.0m \ No newline at end of file diff --git a/tests/fsharp/Compiler/Libraries/Core/Operators/SignTests.fs b/tests/fsharp/Compiler/Libraries/Core/Operators/SignTests.fs new file mode 100644 index 00000000000..751e535d531 --- /dev/null +++ b/tests/fsharp/Compiler/Libraries/Core/Operators/SignTests.fs @@ -0,0 +1,81 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace FSharp.Compiler.UnitTests + +open NUnit.Framework +open FSharp.Compiler.SourceCodeServices +open FSharp.Test.Utilities + +[] +module ``Sign Tests`` = + + [] + let ``Sign of signed types``() = + Assert.areEqual (sign 1y) 1 // byte + Assert.areEqual (sign 1s) 1 // int16 + Assert.areEqual (sign 1) 1 // int32 + Assert.areEqual (sign 1L) 1 // int64 + Assert.areEqual (sign 1.0f) 1 // float + Assert.areEqual (sign 1.0) 1 // double + Assert.areEqual (sign 1.0m) 1 // decimal + Assert.areEqual (sign 0y) 0 // byte + Assert.areEqual (sign 0s) 0 // int16 + Assert.areEqual (sign 0) 0 // int32 + Assert.areEqual (sign 0L) 0 // int64 + Assert.areEqual (sign 0.0f) 0 // float + Assert.areEqual (sign 0.0) 0 // double + Assert.areEqual (sign 0.0m) 0 // decimal + Assert.areEqual (sign -1y) -1 // byte + Assert.areEqual (sign -1s) -1 // int16 + Assert.areEqual (sign -1) -1 // int32 + Assert.areEqual (sign -1L) -1 // int64 + Assert.areEqual (sign -1.0f) -1 // float + Assert.areEqual (sign -1.0) -1 // double + Assert.areEqual (sign -1.0m) -1 // decimal + + // #Regression #Libraries #Operators + // Test sign function on unsigned primitives, should get error. + + [] + let ``Sign of byte``() = + CompilerAssert.TypeCheckSingleError + """ +sign 0uy |> ignore + """ + FSharpErrorSeverity.Error + 1 + (2, 6, 2, 9) + "The type 'byte' does not support the operator 'get_Sign'" + + [] + let ``Sign of uint16``() = + CompilerAssert.TypeCheckSingleError + """ +sign 0us |> ignore + """ + FSharpErrorSeverity.Error + 1 + (2, 6, 2, 9) + "The type 'uint16' does not support the operator 'get_Sign'" + + [] + let ``Sign of uint32``() = + CompilerAssert.TypeCheckSingleError + """ +sign 0u |> ignore + """ + FSharpErrorSeverity.Error + 1 + (2, 6, 2, 8) + "The type 'uint32' does not support the operator 'get_Sign'" + + [] + let ``Sign of uint64``() = + CompilerAssert.TypeCheckSingleError + """ +sign 0uL |> ignore + """ + FSharpErrorSeverity.Error + 1 + (2, 6, 2, 9) + "The type 'uint64' does not support the operator 'get_Sign'" \ No newline at end of file diff --git a/tests/fsharp/Compiler/Libraries/Core/Operators/StringTests.fs b/tests/fsharp/Compiler/Libraries/Core/Operators/StringTests.fs new file mode 100644 index 00000000000..dbb691fb35b --- /dev/null +++ b/tests/fsharp/Compiler/Libraries/Core/Operators/StringTests.fs @@ -0,0 +1,115 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace FSharp.Compiler.UnitTests + +open NUnit.Framework +open System + +[] +module ``String Tests`` = + + type CalcSum(x : int, y: int) = + let mutable x = x + let mutable y = y + + member __.Sum () = x + y + + interface IFormattable with + member x.ToString (format: string, _ : IFormatProvider) = + match format with + | null | "" + | "g" | "G" -> String.Format("X + Y = {0}", x.Sum()) + | "s" | "S" -> x.Sum().ToString() // Short form + | _ -> invalidArg format "Format is wrong!" + + override x.ToString() = (x :> IFormattable).ToString(null, null) + + [] + let ``String of custom type``() = + let calc = CalcSum(10, 20) + Assert.areEqual (string calc) "X + Y = 30" + + let testDelegate = TestDelegate (fun () -> + printfn "%s" (calc.ToString()) + Console.WriteLine("{0:S}", calc) + Console.Write("{0} {1} {2:D}", 10, 20, calc)) + let e = Assert.Throws testDelegate + Assert.areEqual e.ParamName "D" + + // int32 + type Foo = + | A = 1 + | B = 2 + + [] + let ``String of int32 based enum``() = + let a = Foo.A + let r = a :> System.IFormattable + + Assert.areEqual (string a) (string r) + + // uint32 + type Foo2 = + | A = 3u + | B = 4u + + [] + let ``String of uint32 based enum``() = + let a = Foo2.A + let r = a :> System.IFormattable + Assert.areEqual (string a) (string r) + + // char + type Foo3 = + | A = 'a' + | B = 'b' + + [] + let ``String of char based enum``() = + let a = Foo3.A + let r = a :> System.IFormattable + Assert.areEqual (string a) (string r) + + // int16 + type Foo4 = + | A = 1s + | B = 2s + + [] + let ``String of int16 based enum``() = + let a = Foo4.A + let r = a :> System.IFormattable + Assert.areEqual (string a) (string r) + + // uint16 + type Foo5 = + | A = 1us + | B = 2us + + [] + let ``String of uint16 based enum``() = + let a = Foo5.A + let r = a :> System.IFormattable + Assert.areEqual (string a) (string r) + + // sbyte + type Foo6 = + | A = 1y + | B = 2y + + [] + let ``String of sbyte based enum``() = + let a = Foo6.A + let r = a :> System.IFormattable + Assert.areEqual (string a) (string r) + + // byte + type Foo7 = + | A = 1uy + | B = 2uy + + [] + let ``String of byte based enum``() = + let a = Foo7.A + let r = a :> System.IFormattable + Assert.areEqual (string a) (string r) \ No newline at end of file diff --git a/tests/fsharp/FSharpSuite.Tests.fsproj b/tests/fsharp/FSharpSuite.Tests.fsproj index e3532d1ce04..b06425e88dc 100644 --- a/tests/fsharp/FSharpSuite.Tests.fsproj +++ b/tests/fsharp/FSharpSuite.Tests.fsproj @@ -33,24 +33,9 @@ - - - - + - - - - - - - - - - - - @@ -83,6 +68,13 @@ + + + + + + + diff --git a/tests/fsharp/core/members/set-only-property/calls.bsl b/tests/fsharp/core/members/set-only-property/calls.bsl new file mode 100644 index 00000000000..52a50afe857 --- /dev/null +++ b/tests/fsharp/core/members/set-only-property/calls.bsl @@ -0,0 +1,12 @@ + +calls.fsx(18,30,18,31): typecheck error FS0629: Method 'set_Prop2' is not accessible from this code location + +calls.fsx(19,34,19,35): typecheck error FS0629: Method 'set_Prop2' is not accessible from this code location + +calls.fsx(20,24,20,29): typecheck error FS0495: The object constructor 'Class' has no argument or settable return property 'Prop2'. The required signature is new : unit -> fsharp.Class. + +calls.fsx(22,29,22,30): typecheck error FS0629: Method 'set_Prop2' is not accessible from this code location + +calls.fsx(23,29,23,30): typecheck error FS0629: Method 'set_Prop2' is not accessible from this code location + +calls.fsx(24,23,24,28): typecheck error FS0495: The member or object constructor 'mkFs' has no argument or settable return property 'Prop2'. The required signature is static member Maker.mkFs : unit -> fsharp.Class. diff --git a/tests/fsharp/core/members/set-only-property/calls.fsx b/tests/fsharp/core/members/set-only-property/calls.fsx new file mode 100644 index 00000000000..ddd6b365cb3 --- /dev/null +++ b/tests/fsharp/core/members/set-only-property/calls.fsx @@ -0,0 +1,24 @@ +#r "cs.dll" +#r "vb.dll" +#r "fs.dll" +type Maker = + static member mkCs () = csharp.Class() + static member mkVb () = basic.BasicClass() + static member mkFs () = fsharp.Class() +// so long https://github.com/dotnet/fsharp/issues/8351 isn't fixed, Prop1 setters are failing +let a = csharp.Class(Prop1=1) +let b = basic.BasicClass(Prop1=1) +let c = fsharp.Class(Prop1=1) // this one works, inconsistent but correct. + +let aa = Maker.mkCs(Prop1=1) +let bb = Maker.mkVb(Prop1=1) +let cc = Maker.mkFs(Prop1=1) // this one works, inconsistent but correct. + +// those are expected to fail, albeit with inconsistent error messages / marked ranges +let aaa = csharp.Class(Prop2=1) +let bbb = basic.BasicClass(Prop2=1) +let ccc = fsharp.Class(Prop2=1) + +let aaaa = Maker.mkCs(Prop2=1) +let bbbb = Maker.mkVb(Prop2=1) +let cccc = Maker.mkFs(Prop2=1) diff --git a/tests/fsharp/core/members/set-only-property/cs.cs b/tests/fsharp/core/members/set-only-property/cs.cs new file mode 100644 index 00000000000..18818edcf45 --- /dev/null +++ b/tests/fsharp/core/members/set-only-property/cs.cs @@ -0,0 +1,8 @@ +namespace csharp +{ + public class Class + { + public int Prop1 { set; private get; } + public int Prop2 { private set; get; } + } +} \ No newline at end of file diff --git a/tests/fsharp/core/members/set-only-property/fs.fs b/tests/fsharp/core/members/set-only-property/fs.fs new file mode 100644 index 00000000000..9b05bc67e70 --- /dev/null +++ b/tests/fsharp/core/members/set-only-property/fs.fs @@ -0,0 +1,8 @@ +namespace fsharp +type Class () = + let mutable v = 0 + member x.Prop1 with set(value) = v <- value + and private get () = v + + member x.Prop2 with private set(value) = v <- value + and public get () = v diff --git a/tests/fsharp/core/members/set-only-property/vb.vb b/tests/fsharp/core/members/set-only-property/vb.vb new file mode 100644 index 00000000000..c6a4865c012 --- /dev/null +++ b/tests/fsharp/core/members/set-only-property/vb.vb @@ -0,0 +1,21 @@ +namespace basic + public class BasicClass + dim v as integer + public property Prop1 as integer + private get + return v + end get + set(value as integer) + v = value + end set + end property + public property Prop2 as integer + get + return v + end get + private set(value as integer) + v = value + end set + end property + end class +end namespace \ No newline at end of file diff --git a/tests/fsharp/tests.fs b/tests/fsharp/tests.fs index c9d1abb6950..1a2be765dc5 100644 --- a/tests/fsharp/tests.fs +++ b/tests/fsharp/tests.fs @@ -1813,6 +1813,16 @@ module CoreTests = fsc cfg "%s -o:xmlverify.exe -g" cfg.fsc_flags ["xmlverify.fs"] peverifyWithArgs cfg "/nologo" "xmlverify.exe" + + + [] + let ``property setter in method or constructor`` () = + let cfg = testConfig' "core/members/set-only-property" + csc cfg @"%s /target:library /out:cs.dll" cfg.csc_flags ["cs.cs"] + vbc cfg @"%s /target:library /out:vb.dll" cfg.vbc_flags ["vb.vb"] + fsc cfg @"%s /target:library /out:fs.dll" cfg.fsc_flags ["fs.fs"] + singleNegTest cfg "calls" + #endif module VersionTests = diff --git a/tests/fsharpqa/Source/CompilerOptions/fsc/langversion/langversionhelp.437.1033.bsl b/tests/fsharpqa/Source/CompilerOptions/fsc/langversion/langversionhelp.437.1033.bsl index b7f6805220b..cb2855709a4 100644 --- a/tests/fsharpqa/Source/CompilerOptions/fsc/langversion/langversionhelp.437.1033.bsl +++ b/tests/fsharpqa/Source/CompilerOptions/fsc/langversion/langversionhelp.437.1033.bsl @@ -5,4 +5,4 @@ latest latestmajor 4.6 4.7 -5.0 (Default) \ No newline at end of file +5.0 (Default) diff --git a/tests/fsharpqa/Source/CompilerOptions/fsi/langversion/langversionhelp.437.1033.bsl b/tests/fsharpqa/Source/CompilerOptions/fsi/langversion/langversionhelp.437.1033.bsl index b7f6805220b..cb2855709a4 100644 --- a/tests/fsharpqa/Source/CompilerOptions/fsi/langversion/langversionhelp.437.1033.bsl +++ b/tests/fsharpqa/Source/CompilerOptions/fsi/langversion/langversionhelp.437.1033.bsl @@ -5,4 +5,4 @@ latest latestmajor 4.6 4.7 -5.0 (Default) \ No newline at end of file +5.0 (Default) diff --git a/tests/fsharpqa/Source/ErrorMessages/ConfusingTypeName/app.fs b/tests/fsharpqa/Source/ErrorMessages/ConfusingTypeName/app.fs deleted file mode 100644 index 130c63a7d55..00000000000 --- a/tests/fsharpqa/Source/ErrorMessages/ConfusingTypeName/app.fs +++ /dev/null @@ -1,22 +0,0 @@ -//This expression was expected to have type -//'A (liba, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null)' -//but here has type -//'A (libb, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null)' - - -//This expression was expected to have type -//'B (liba, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null)' -//but here has type -//'B (libb, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null)' - - -let a = AMaker.makeA() -let otherA = OtherAMaker.makeOtherA() -printfn "%A %A" (a.GetType().AssemblyQualifiedName) (otherA.GetType().AssemblyQualifiedName) -printfn "%A" (a = otherA) - -let b = AMaker.makeB() -let otherB = OtherAMaker.makeOtherB() -printfn "%A %A" (b.GetType().AssemblyQualifiedName) (otherB.GetType().AssemblyQualifiedName) -printfn "%A" (b = otherB) - \ No newline at end of file diff --git a/tests/fsharpqa/Source/ErrorMessages/ConfusingTypeName/compile.bat b/tests/fsharpqa/Source/ErrorMessages/ConfusingTypeName/compile.bat deleted file mode 100644 index abcfa42e592..00000000000 --- a/tests/fsharpqa/Source/ErrorMessages/ConfusingTypeName/compile.bat +++ /dev/null @@ -1,6 +0,0 @@ -rem if you want to try it out without running the whole suite -csc -t:library -out:liba.dll liba-and-b.cs -csc -t:library -out:libb.dll liba-and-b.cs -fsc --target:library -r:liba.dll --out:libc.dll libc.fs -fsc --target:library -r:libb.dll --out:libd.dll libd.fs -fsc -r:liba.dll -r:libb.dll -r:libc.dll -r:libd.dll app.fs diff --git a/tests/fsharpqa/Source/ErrorMessages/ConfusingTypeName/env.lst b/tests/fsharpqa/Source/ErrorMessages/ConfusingTypeName/env.lst deleted file mode 100644 index 8189ed0b1f8..00000000000 --- a/tests/fsharpqa/Source/ErrorMessages/ConfusingTypeName/env.lst +++ /dev/null @@ -1,3 +0,0 @@ -# see compile.bat for clearer steps, aim is to get message highlighting fix for https://github.com/Microsoft/visualfsharp/issues/2561 - SOURCE="app.fs" SCFLAGS="-r:liba.dll -r:libb.dll -r:libc.dll -r:libd.dll" PRECMD="\$CSC_PIPE -t:library -out:liba.dll liba-and-b.cs && \$CSC_PIPE -t:library -out:libb.dll liba-and-b.cs && fsc --target:library -r:liba.dll --out:libc.dll libc.fs && fsc --target:library -r:libb.dll --out:libd.dll libd.fs" - \ No newline at end of file diff --git a/tests/fsharpqa/Source/ErrorMessages/ConfusingTypeName/liba-and-b.cs b/tests/fsharpqa/Source/ErrorMessages/ConfusingTypeName/liba-and-b.cs deleted file mode 100644 index 9e1d2d24b31..00000000000 --- a/tests/fsharpqa/Source/ErrorMessages/ConfusingTypeName/liba-and-b.cs +++ /dev/null @@ -1,2 +0,0 @@ -public class A { } -public class B { } \ No newline at end of file diff --git a/tests/fsharpqa/Source/ErrorMessages/ConfusingTypeName/libc.fs b/tests/fsharpqa/Source/ErrorMessages/ConfusingTypeName/libc.fs deleted file mode 100644 index 4e1450a4149..00000000000 --- a/tests/fsharpqa/Source/ErrorMessages/ConfusingTypeName/libc.fs +++ /dev/null @@ -1,3 +0,0 @@ -module AMaker -let makeA () : A = A() -let makeB () = B<_>() diff --git a/tests/fsharpqa/Source/ErrorMessages/ConfusingTypeName/libd.fs b/tests/fsharpqa/Source/ErrorMessages/ConfusingTypeName/libd.fs deleted file mode 100644 index 5458451d7cb..00000000000 --- a/tests/fsharpqa/Source/ErrorMessages/ConfusingTypeName/libd.fs +++ /dev/null @@ -1,3 +0,0 @@ -module OtherAMaker -let makeOtherA () : A = A() -let makeOtherB () = B<_>() \ No newline at end of file diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/AbsOnIntegers01.fs b/tests/fsharpqa/Source/Libraries/Core/Operators/AbsOnIntegers01.fs deleted file mode 100644 index 76687657876..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/AbsOnIntegers01.fs +++ /dev/null @@ -1,15 +0,0 @@ -// #Regression #Libraries #Operators -// Regression test for FSHARP1.0:3470 - exception on abs of native integer - -#light - -let res = - abs -1y = 1y // signed byte - && abs -1s = 1s // int16 - && abs -1l = 1l // int32 - && abs -1n = 1n // nativeint - && abs -1L = 1L // int64 - && abs -1I = 1I // bigint - -if not res then exit 1 -exit 0 diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/CastOperator.fs b/tests/fsharpqa/Source/Libraries/Core/Operators/CastOperator.fs deleted file mode 100644 index a79a04119b2..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/CastOperator.fs +++ /dev/null @@ -1,11 +0,0 @@ -// #Regression #Libraries #Operators -// Regression test for FSHARP1.0:1247 -// Precedence of type annotations :> and :?> over preceeding expression forms, e.g. if-then-else etc. -// - -open System -let x = 2 :> Object -let y = [(2 :> Object)] -let z = [2 :> Object] - -exit 0 diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/E_EqualityAndHash01.fs b/tests/fsharpqa/Source/Libraries/Core/Operators/E_EqualityAndHash01.fs deleted file mode 100644 index 46f3d2cd725..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/E_EqualityAndHash01.fs +++ /dev/null @@ -1,8 +0,0 @@ -// #Regression #Libraries #Operators -// Regression test for FSHARP1.0:5436 -// You should not be able to hash F# function values) -// Note: most positive cases already covered under fsharp\typecheck\sigs -// I'm adding this simple one since I did not see it there. -//The type '\('a -> 'a\)' does not support the 'equality' constraint because it is a function type - -let q = hash id diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/E_sign02.fs b/tests/fsharpqa/Source/Libraries/Core/Operators/E_sign02.fs deleted file mode 100644 index 7a368182e02..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/E_sign02.fs +++ /dev/null @@ -1,12 +0,0 @@ -// #Regression #Libraries #Operators -// Test sign function on unsigned primitives, should get error. - -//The type 'byte' does not support the operator 'get_Sign'$ -//The type 'uint16' does not support the operator 'get_Sign'$ -//The type 'uint32' does not support the operator 'get_Sign'$ -//The type 'uint64' does not support the operator 'get_Sign'$ - -if sign 0uy <> 0 then exit 1 // byte -if sign 0us <> 0 then exit 1 // int16 -if sign 0u <> 0 then exit 1 // int32 -if sign 0uL <> 0 then exit 1 // int64 diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/EqualityAndUncheckedHash01.fs b/tests/fsharpqa/Source/Libraries/Core/Operators/EqualityAndUncheckedHash01.fs deleted file mode 100644 index 7ae622955eb..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/EqualityAndUncheckedHash01.fs +++ /dev/null @@ -1,10 +0,0 @@ -// #Regression #Libraries #Operators -// Regression test for FSHARP1.0:5436 -// You should not be able to hash F# function values -// Note: most positive cases already covered under fsharp\typecheck\sigs -// I'm adding this simple one since I did not see it there. -// -module TestModule - -// This is ok (unchecked) -let p = Unchecked.hash id diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/Pow_Constrains.fs b/tests/fsharpqa/Source/Libraries/Core/Operators/Pow_Constrains.fs deleted file mode 100644 index f54171f6ccf..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/Pow_Constrains.fs +++ /dev/null @@ -1,16 +0,0 @@ -// #Regression #Libraries #Operators -// Regression test for FSHARP1.0:4487 -// Feature request: loosen Pow operator constraints - -type T(x : float, y : float) = - static let mutable m = false - static member Pow (g: T, e: float) = m <- true - g - static member Check() = m - -let t = new T(1.,2.) - -let c = t ** 3. // OK! - -exit <| if T.Check() then 0 else 1 - diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/StringOnEnum01.fs b/tests/fsharpqa/Source/Libraries/Core/Operators/StringOnEnum01.fs deleted file mode 100644 index 7fd2ceccddb..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/StringOnEnum01.fs +++ /dev/null @@ -1,68 +0,0 @@ -// #Regression #Libraries #Operators -// Regression for FSHARP1.0:5995 -// Calling "string" on an enum results in the integer value rather than the ToString name (possibly other static optimization issues?) - -module M - -// int32 -type Foo = - | A = 1 - | B = 2 - -let a = Foo.A -let r = a :> System.IFormattable -if (string a) <> (string r) then exit 1 - -// uint32 -type Foo2 = - | A = 3u - | B = 4u - -let a2 = Foo2.A -let r2 = a :> System.IFormattable -if (string a2) <> (string r2) then exit 1 - -// char : see FSHARP1.0:6228 -//type Foo3 = -// | A = 'a' -// | B = 'b' - -//let a3 = Foo3.A -//let r3 = a :> System.IFormattable -//if (string a3) <> (string r3) then exit 1 - -// int16 -type Foo4 = - | A = 1s - | B = 2s - -let a4 = Foo4.A -let r4 = a :> System.IFormattable -if (string a4) <> (string r4) then exit 1 - -// uint16 -type Foo5 = - | A = 1us - | B = 2us - -let a5 = Foo5.A -let r5 = a :> System.IFormattable -if (string a5) <> (string r5) then exit 1 - -// sbyte -type Foo6 = - | A = 1y - | B = 2y - -let a6 = Foo6.A -let r6 = a :> System.IFormattable -if (string a6) <> (string r6) then exit 1 - -// byte -type Foo7 = - | A = 1uy - | B = 2uy - -let a7 = Foo7.A -let r7 = a :> System.IFormattable -if (string a7) <> (string r7) then exit 1 diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/e_AbsOnIntegers02.fs b/tests/fsharpqa/Source/Libraries/Core/Operators/e_AbsOnIntegers02.fs deleted file mode 100644 index 60ec1eb5da6..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/e_AbsOnIntegers02.fs +++ /dev/null @@ -1,17 +0,0 @@ -// #Regression #Libraries #Operators -// Regression test for FSHARP1.0:3470 - exception on abs of native integer -//The type 'byte' does not support the operator 'Abs'$ -//The type 'uint16' does not support the operator 'Abs'$ -//The type 'uint32' does not support the operator 'Abs'$ -//The type 'uint32' does not support the operator 'Abs'$ -//The type 'unativeint' does not support the operator 'Abs'$ -//The type 'uint64' does not support the operator 'Abs'$ -//The type 'uint64' does not support the operator 'Abs'$ - -abs -1uy // byte -abs -1us // uint16 -abs -1ul // uint32 -abs -1u // uint32 -abs -1un // unativeint -abs -1uL // uint64 -abs -1UL // uint64 diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst b/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst deleted file mode 100644 index 3b893973508..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst +++ /dev/null @@ -1,13 +0,0 @@ - SOURCE=Pow_Constrains.fs SCFLAGS=--warnaserror # Pow_Constrains.fs - SOURCE=sign01.fs # sign01.fs - SOURCE=E_sign02.fs SCFLAGS=--test:ErrorRanges # E_sign02.fs - SOURCE=round01.fs # round01.fs - SOURCE=string01.fs # string01.fs - SOURCE=AbsOnIntegers01.fs # AbsOnIntegers01.fs - SOURCE=E_AbsOnIntegers02.fs SCFLAGS="--test:ErrorRanges --nowarn:20" # E_AbsOnIntegers02.fs - SOURCE=CastOperator.fs # CastOperator.fs - - SOURCE=EqualityAndUncheckedHash01.fs SCFLAGS=-a # EqualityAndUncheckedHash01.fs - SOURCE=E_EqualityAndHash01.fs SCFLAGS=--test:ErrorRanges # E_EqualityAndHash01.fs - - SOURCE=StringOnEnum01.fs # StringOnEnum01.fs \ No newline at end of file diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/round01.fs b/tests/fsharpqa/Source/Libraries/Core/Operators/round01.fs deleted file mode 100644 index a9287100a85..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/round01.fs +++ /dev/null @@ -1,60 +0,0 @@ -// #Libraries #Operators -#light - -// Test the round function - -// Identity -for i in [1 .. 10000] do - if i |> float |> round <> float i then exit 1 - if i |> float32 |> round <> float32 i then exit 1 - if i |> decimal |> round <> decimal i then exit 1 - -// Round down -if round 1.1 <> 1.0 then exit 1 -if round 1.2 <> 1.0 then exit 1 -if round 1.3 <> 1.0 then exit 1 -if round 1.4 <> 1.0 then exit 1 - -if round 1.1f <> 1.0f then exit 1 -if round 1.2f <> 1.0f then exit 1 -if round 1.3f <> 1.0f then exit 1 -if round 1.4f <> 1.0f then exit 1 - -if round 1.1m <> 1.0m then exit 1 -if round 1.2m <> 1.0m then exit 1 -if round 1.3m <> 1.0m then exit 1 -if round 1.4m <> 1.0m then exit 1 - -// Round down -if round 1.6 <> 2.0 then exit 1 -if round 1.7 <> 2.0 then exit 1 -if round 1.8 <> 2.0 then exit 1 -if round 1.9 <> 2.0 then exit 1 - -if round 1.6f <> 2.0f then exit 1 -if round 1.7f <> 2.0f then exit 1 -if round 1.8f <> 2.0f then exit 1 -if round 1.9f <> 2.0f then exit 1 - -if round 1.6m <> 2.0m then exit 1 -if round 1.7m <> 2.0m then exit 1 -if round 1.8m <> 2.0m then exit 1 -if round 1.9m <> 2.0m then exit 1 - -// Midpoint rounding. If between two numbers, round to the 'even' one. - -if round 1.5 <> 2.0 then exit 1 -if round 1.5f <> 2.0f then exit 1 -if round 1.5m <> 2.0m then exit 1 - -if round 2.5 <> 2.0 then exit 1 -if round 2.5f <> 2.0f then exit 1 -if round 2.5m <> 2.0m then exit 1 - -// If not midpoint, round to nearest as usual - -if round 2.500001 <> 3.0 then exit 1 -if round 2.500001f <> 3.0f then exit 1 -if round 2.500001m <> 3.0m then exit 1 - -exit 0 diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/sign01.fs b/tests/fsharpqa/Source/Libraries/Core/Operators/sign01.fs deleted file mode 100644 index f181ba4ca89..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/sign01.fs +++ /dev/null @@ -1,34 +0,0 @@ -// #Libraries #Operators -#light - -// Test the 'sign' library function - -// Positive sign -if sign 1y <> 1 then exit 1 // byte -if sign 1s <> 1 then exit 1 // int16 -if sign 1 <> 1 then exit 1 // int32 -if sign 1L <> 1 then exit 1 // int64 -if sign 1.0f <> 1 then exit 1 // float -if sign 1.0 <> 1 then exit 1 // double -if sign 1.0m <> 1 then exit 1 // decimal - -// Zero -if sign 0y <> 0 then exit 1 // byte -if sign 0s <> 0 then exit 1 // int16 -if sign 0 <> 0 then exit 1 // int32 -if sign 0L <> 0 then exit 1 // int64 -if sign 0.0f <> 0 then exit 1 // float -if sign 0.0 <> 0 then exit 1 // double -if sign 0.0m <> 0 then exit 1 // decimal - -// Negative sign -if sign -1y <> -1 then exit 1 // byte -if sign -1s <> -1 then exit 1 // int16 -if sign -1 <> -1 then exit 1 // int32 -if sign -1L <> -1 then exit 1 // int64 -if sign -1.0f <> -1 then exit 1 // float -if sign -1.0 <> -1 then exit 1 // double -if sign -1.0m <> -1 then exit 1 // decimal - -// All clear! -exit 0 diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/string01.fs b/tests/fsharpqa/Source/Libraries/Core/Operators/string01.fs deleted file mode 100644 index 881cd5c28a2..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/string01.fs +++ /dev/null @@ -1,44 +0,0 @@ -// #Regression #Libraries #Operators -open System - -// Regression test for FSHARP1.0:3977 - Make "string" function work for decimal and user-defined IFormattable types. - -type CalcSum(x : int, y: int) = - let mutable x = x - let mutable y = y - - member this.Sum () = x + y - - interface IFormattable with - member x.ToString (format: string, provider : IFormatProvider) = - match format with - | null | "" - | "g" | "G" -> - String.Format("X + Y = {0}", x.Sum()) - | "s" | "S" -> - // Short form - x.Sum().ToString() - | _ -> - invalidArg format "Format is wrong!" - - override x.ToString() = (x :> IFormattable).ToString(null, null) - -let calc = CalcSum(10, 20) - -// test string function -match string calc with -| "X + Y = 30" -> () -| _ -> exit 1 - -// test with Console.WriteLine -try - printfn "%s" (calc.ToString()) - Console.WriteLine("{0:S}", calc) - Console.Write("{0} {1} {2:D}", 10, 20, calc) -with - | :? ArgumentException as e -> - match e.ParamName with - | "D" -> exit 0 - | _ -> exit 2 - -exit 1 diff --git a/tests/fsharpqa/Source/test.lst b/tests/fsharpqa/Source/test.lst index 8a3aeac76b2..95afc5893b4 100644 --- a/tests/fsharpqa/Source/test.lst +++ b/tests/fsharpqa/Source/test.lst @@ -266,8 +266,6 @@ Misc01 Libraries\Core\Operators Misc01 Libraries\Core\Reflection Misc01 Libraries\Core\Unchecked Misc01 Warnings -Misc01 ErrorMessages\UnitGenericAbstractType -Misc01 ErrorMessages\ConfusingTypeName Misc02 Libraries\Portable Misc02 Misc diff --git a/vsintegration/src/FSharp.Editor/Classification/ClassificationDefinitions.fs b/vsintegration/src/FSharp.Editor/Classification/ClassificationDefinitions.fs index 749c3ceed7a..1dea67f4f35 100644 --- a/vsintegration/src/FSharp.Editor/Classification/ClassificationDefinitions.fs +++ b/vsintegration/src/FSharp.Editor/Classification/ClassificationDefinitions.fs @@ -21,36 +21,45 @@ open FSharp.Compiler.SourceCodeServices [] module internal FSharpClassificationTypes = - let [] Function = "FSharp.Function" let [] MutableVar = "FSharp.MutableVar" - let [] Printf = "FSharp.Printf" - let [] ReferenceType = ClassificationTypeNames.ClassName - let [] Module = ClassificationTypeNames.ModuleName - let [] ValueType = ClassificationTypeNames.StructName - let [] Keyword = ClassificationTypeNames.Keyword - let [] Enum = ClassificationTypeNames.EnumName - let [] Property = "FSharp.Property" - let [] Interface = ClassificationTypeNames.InterfaceName - let [] TypeArgument = ClassificationTypeNames.TypeParameterName - let [] Operator = ClassificationTypeNames.Operator let [] Disposable = "FSharp.Disposable" let getClassificationTypeName = function - | SemanticClassificationType.ReferenceType -> ReferenceType - | SemanticClassificationType.Module -> Module - | SemanticClassificationType.ValueType -> ValueType - | SemanticClassificationType.Function -> Function + | SemanticClassificationType.MutableRecordField | SemanticClassificationType.MutableVar -> MutableVar - | SemanticClassificationType.Printf -> Printf + | SemanticClassificationType.DisposableValue + | SemanticClassificationType.DisposableType -> Disposable + | SemanticClassificationType.NameSpace -> ClassificationTypeNames.NamespaceName + | SemanticClassificationType.Exception + | SemanticClassificationType.Module + | SemanticClassificationType.Type + | SemanticClassificationType.TypeDef + | SemanticClassificationType.ConstructorForReferenceType + | SemanticClassificationType.Printf + | SemanticClassificationType.ReferenceType -> ClassificationTypeNames.ClassName + | SemanticClassificationType.ConstructorForValueType + | SemanticClassificationType.ValueType -> ClassificationTypeNames.StructName | SemanticClassificationType.ComputationExpression - | SemanticClassificationType.IntrinsicFunction -> Keyword + | SemanticClassificationType.IntrinsicFunction -> ClassificationTypeNames.Keyword | SemanticClassificationType.UnionCase - | SemanticClassificationType.Enumeration -> Enum - | SemanticClassificationType.Property -> Property - | SemanticClassificationType.Interface -> Interface - | SemanticClassificationType.TypeArgument -> TypeArgument - | SemanticClassificationType.Operator -> Operator - | SemanticClassificationType.Disposable -> Disposable + | SemanticClassificationType.Enumeration -> ClassificationTypeNames.EnumName + | SemanticClassificationType.Field + | SemanticClassificationType.UnionCaseField -> ClassificationTypeNames.FieldName + | SemanticClassificationType.Interface -> ClassificationTypeNames.InterfaceName + | SemanticClassificationType.TypeArgument -> ClassificationTypeNames.TypeParameterName + | SemanticClassificationType.Operator -> ClassificationTypeNames.Operator + | SemanticClassificationType.Function + | SemanticClassificationType.Method -> ClassificationTypeNames.MethodName + | SemanticClassificationType.ExtensionMethod -> ClassificationTypeNames.ExtensionMethodName + | SemanticClassificationType.Literal -> ClassificationTypeNames.ConstantName + | SemanticClassificationType.Property + | SemanticClassificationType.RecordFieldAsFunction + | SemanticClassificationType.RecordField -> ClassificationTypeNames.PropertyName // TODO - maybe pick something that isn't white by default like Property? + | SemanticClassificationType.NamedArgument -> ClassificationTypeNames.LabelName + | SemanticClassificationType.Event -> ClassificationTypeNames.EventName + | SemanticClassificationType.Delegate -> ClassificationTypeNames.DelegateName + | SemanticClassificationType.Value -> ClassificationTypeNames.Identifier + | SemanticClassificationType.LocalValue -> ClassificationTypeNames.LocalName module internal ClassificationDefinitions = @@ -73,13 +82,11 @@ module internal ClassificationDefinitions = let themeService = serviceProvider.GetService(typeof) :?> IVsColorThemeService themeService.CurrentTheme.ThemeId - let colorData = // name, (light, dark) - [ FSharpClassificationTypes.Function, (Colors.Black, Color.FromRgb(220uy, 220uy, 220uy)) - FSharpClassificationTypes.MutableVar, (Color.FromRgb(160uy, 128uy, 0uy), Color.FromRgb(255uy, 210uy, 28uy)) - FSharpClassificationTypes.Printf, (Color.FromRgb(43uy, 145uy, 175uy), Color.FromRgb(78uy, 220uy, 176uy)) - FSharpClassificationTypes.Property, (Colors.Black, Color.FromRgb(220uy, 220uy, 220uy)) - FSharpClassificationTypes.Disposable, (Color.FromRgb(43uy, 145uy, 175uy), Color.FromRgb(78uy, 220uy, 176uy)) ] - + let customColorData = // name, (light, dark) + [ + FSharpClassificationTypes.MutableVar, (Color.FromRgb(160uy, 128uy, 0uy), Color.FromRgb(255uy, 210uy, 28uy)) + FSharpClassificationTypes.Disposable, (Colors.Green, Color.FromRgb(2uy, 183uy, 43uy)) + ] let setColors _ = let fontAndColorStorage = serviceProvider.GetService(typeof) :?> IVsFontAndColorStorage @@ -90,15 +97,16 @@ module internal ClassificationDefinitions = let formatMap = classificationformatMapService.GetClassificationFormatMap(category = "text") try formatMap.BeginBatchUpdate() - for ctype, (light, dark) in colorData do + for ctype, (light, dark) in customColorData do // we don't touch the changes made by the user if fontAndColorStorage.GetItem(ctype, Array.zeroCreate 1) <> VSConstants.S_OK then let ict = classificationTypeRegistry.GetClassificationType(ctype) let oldProps = formatMap.GetTextProperties(ict) - let newProps = match getCurrentThemeId() with - | LightTheme -> oldProps.SetForeground light - | DarkTheme -> oldProps.SetForeground dark - | UnknownTheme -> oldProps + let newProps = + match getCurrentThemeId() with + | LightTheme -> oldProps.SetForeground light + | DarkTheme -> oldProps.SetForeground dark + | UnknownTheme -> oldProps formatMap.SetTextProperties(ict, newProps) fontAndColorStorage.CloseCategory() |> ignore finally formatMap.EndBatchUpdate() @@ -108,7 +116,7 @@ module internal ClassificationDefinitions = interface IDisposable with member __.Dispose() = VSColorTheme.remove_ThemeChanged handler member __.GetColor(ctype) = - let light, dark = colorData |> Map.ofList |> Map.find ctype + let light, dark = customColorData |> Map.ofList |> Map.find ctype match getCurrentThemeId() with | LightTheme -> Nullable light | DarkTheme -> Nullable dark @@ -116,32 +124,13 @@ module internal ClassificationDefinitions = interface ISetThemeColors with member this.SetColors() = setColors() - - [] - let FSharpFunctionClassificationType : ClassificationTypeDefinition = null - [] let FSharpMutableVarClassificationType : ClassificationTypeDefinition = null - [] - let FSharpPrintfClassificationType : ClassificationTypeDefinition = null - - [] - let FSharpPropertyClassificationType : ClassificationTypeDefinition = null [] let FSharpDisposableClassificationType : ClassificationTypeDefinition = null - [)>] - [] - [] - [] - [] - type internal FSharpFunctionTypeFormat() as self = - inherit ClassificationFormatDefinition() - - do self.DisplayName <- SR.FSharpFunctionsOrMethodsClassificationType() - [)>] [] [] @@ -153,27 +142,6 @@ module internal ClassificationDefinitions = do self.DisplayName <- SR.FSharpMutableVarsClassificationType() self.ForegroundColor <- theme.GetColor FSharpClassificationTypes.MutableVar - [)>] - [] - [] - [] - [] - type internal FSharpPrintfTypeFormat [](theme: ThemeColors) as self = - inherit ClassificationFormatDefinition() - - do self.DisplayName <- SR.FSharpPrintfFormatClassificationType() - self.ForegroundColor <- theme.GetColor FSharpClassificationTypes.Printf - - [)>] - [] - [] - [] - [] - type internal FSharpPropertyFormat() as self = - inherit ClassificationFormatDefinition() - - do self.DisplayName <- SR.FSharpPropertiesClassificationType() - [)>] [] [] diff --git a/vsintegration/src/FSharp.ProjectSystem.PropertyPages/FSharp.PropertiesPages.vbproj b/vsintegration/src/FSharp.ProjectSystem.PropertyPages/FSharp.PropertiesPages.vbproj index 716a450a971..855ef4c5c21 100644 --- a/vsintegration/src/FSharp.ProjectSystem.PropertyPages/FSharp.PropertiesPages.vbproj +++ b/vsintegration/src/FSharp.ProjectSystem.PropertyPages/FSharp.PropertiesPages.vbproj @@ -92,46 +92,24 @@ - - UserControl - - - UserControl - - - Form - + + + - - UserControl - - - UserControl - - - UserControl - + + + - - UserControl - - - UserControl - + + - - Form - + - - Form - - - UserControl - + + diff --git a/vsintegration/tests/UnitTests/SemanticColorizationServiceTests.fs b/vsintegration/tests/UnitTests/SemanticColorizationServiceTests.fs index 46c2f265680..e1591ed0cb1 100644 --- a/vsintegration/tests/UnitTests/SemanticColorizationServiceTests.fs +++ b/vsintegration/tests/UnitTests/SemanticColorizationServiceTests.fs @@ -7,6 +7,7 @@ open Microsoft.VisualStudio.FSharp.Editor open FSharp.Compiler.SourceCodeServices open FSharp.Compiler open Microsoft.CodeAnalysis.Text +open Microsoft.CodeAnalysis.Classification [] type SemanticClassificationServiceTests() = @@ -57,13 +58,13 @@ type SemanticClassificationServiceTests() = let anyData = ranges |> List.exists (fun struct (range, sct) -> Range.rangeContainsPos range markerPos && ((FSharpClassificationTypes.getClassificationTypeName sct) = classificationType)) Assert.False(anyData, "Classification data was found when it wasn't expected.") - [] - [] - [] - [] - [] - [] - [] + [] + [] + [] + [] + [] + [] + [] member __.Measured_Types(marker: string, classificationType: string) = verifyClassificationAtEndOfMarker( """#light (*Light*)