Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/8.0.300.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* Fix release inline optimization, which leads to MethodAccessException if used with `assembly:InternalsVisibleTo`` attribute. ([Issue #16105](https://github.com/dotnet/fsharp/issues/16105), ([PR #16737](https://github.com/dotnet/fsharp/pull/16737))
* Enforce AttributeTargets on let values and functions. ([PR #16692](https://github.com/dotnet/fsharp/pull/16692))
* Enforce AttributeTargets on union case declarations. ([PR #16764](https://github.com/dotnet/fsharp/pull/16764))
* Disallow using base to invoke an abstract base method. ([Issue #13926](https://github.com/dotnet/fsharp/issues/13926), [PR #16773](https://github.com/dotnet/fsharp/pull/16773))

### Added

Expand Down
8 changes: 6 additions & 2 deletions docs/release-notes/.Language/8.0.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### Added
### Fixed

* `while!` ([Language suggestion #1038](https://github.com/fsharp/fslang-suggestions/issues/1038), [PR #14238](https://github.com/dotnet/fsharp/pull/14238))
* Disallow using base to invoke an abstract base method ([Issue #13926](https://github.com/dotnet/fsharp/issues/13926), [PR #16773](https://github.com/dotnet/fsharp/pull/16773))

### Added

* `while!` ([Language suggestion #1038](https://github.com/fsharp/fslang-suggestions/issues/1038), [PR #14238](https://github.com/dotnet/fsharp/pull/14238))
6 changes: 2 additions & 4 deletions src/Compiler/AbstractIL/il.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5640,10 +5640,8 @@ let resolveILMethodRefWithRescope r (td: ILTypeDef) (mref: ILMethodRef) =
possibles
|> List.filter (fun md ->
mref.CallingConv = md.CallingConv
&&
// REVIEW: this uses equality on ILType. For CMOD_OPTIONAL this is not going to be correct
(md.Parameters, argTypes)
||> List.lengthsEqAndForall2 (fun p1 p2 -> r p1.Type = p2)
&& (md.Parameters, argTypes)
||> List.lengthsEqAndForall2 (fun p1 p2 -> r p1.Type = p2)
&&
// REVIEW: this uses equality on ILType. For CMOD_OPTIONAL this is not going to be correct
r md.Return.Type = retType)
Expand Down
12 changes: 6 additions & 6 deletions src/Compiler/Checking/PostInferenceChecks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1307,14 +1307,14 @@ and CheckILBaseCall cenv env (ilMethRef, enclTypeInst, methInst, retTypes, tyarg
match tryTcrefOfAppTy g baseVal.Type with
| ValueSome tcref when tcref.IsILTycon ->
try
// This is awkward - we have to explicitly re-resolve back to the IL metadata to determine if the method is abstract.
// We believe this may be fragile in some situations, since we are using the Abstract IL code to compare
// type equality, and it would be much better to remove any F# dependency on that implementation of IL type
// equality. It would be better to make this check in tc.fs when we have the Abstract IL metadata for the method to hand.
let mdef = resolveILMethodRef tcref.ILTyconRawMetadata ilMethRef
let mdef =
match tcref.ILTyconInfo with
| TILObjectReprData(scoref, _, _) ->
resolveILMethodRefWithRescope (rescopeILType scoref) tcref.ILTyconRawMetadata ilMethRef

if mdef.IsAbstract then
errorR(Error(FSComp.SR.tcCannotCallAbstractBaseMember(mdef.Name), m))
with _ -> () // defensive coding
with _ -> ()
| _ -> ()

CheckTypeInstNoByrefs cenv env m tyargs
Expand Down
20 changes: 10 additions & 10 deletions src/Compiler/FSharp.Compiler.Service.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@
<InternalsVisibleTo Include="LanguageServiceProfiling" />
<InternalsVisibleTo Include="FSharp.Compiler.Benchmarks" />
<InternalsVisibleTo Include="HistoricalBenchmark" />
<InternalsVisibleTo Include="FSharp.Test.Utilities" />
<InternalsVisibleTo Include="FSharp.Editor" />
<InternalsVisibleTo Include="FSharp.Test.Utilities" />
<InternalsVisibleTo Include="FSharp.Editor" />
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -365,8 +365,8 @@
<Compile Include="Checking\CheckIncrementalClasses.fs" />
<Compile Include="Checking\CheckDeclarations.fsi" />
<Compile Include="Checking\CheckDeclarations.fs" />
<Compile Include="Checking\SignatureHash.fsi" />
<Compile Include="Checking\SignatureHash.fs" />
<Compile Include="Checking\SignatureHash.fsi" />
<Compile Include="Checking\SignatureHash.fs" />
<Compile Include="Optimize\Optimizer.fsi" />
<Compile Include="Optimize\Optimizer.fs" />
<Compile Include="Optimize\DetupleArgs.fsi" />
Expand Down Expand Up @@ -504,12 +504,12 @@
<Compile Include="Service\QuickParse.fsi" />
<Compile Include="Service\QuickParse.fs" />
<Compile Include="Service\FSharpCheckerResults.fsi" />
<Compile Include="Service\FSharpCheckerResults.fs" />
<Compile Include="Service\FSharpProjectSnapshot.fs" />
<Compile Include="Service\BackgroundCompiler.fsi" />
<Compile Include="Service\BackgroundCompiler.fs" />
<Compile Include="Service\TransparentCompiler.fsi" />
<Compile Include="Service\TransparentCompiler.fs" />
<Compile Include="Service\FSharpCheckerResults.fs" />
<Compile Include="Service\FSharpProjectSnapshot.fs" />
<Compile Include="Service\BackgroundCompiler.fsi" />
<Compile Include="Service\BackgroundCompiler.fs" />
<Compile Include="Service\TransparentCompiler.fsi" />
<Compile Include="Service\TransparentCompiler.fs" />
<Compile Include="Service\service.fsi" />
<Compile Include="Service\service.fs" />
<Compile Include="Service\ServiceInterfaceStubGenerator.fsi" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,75 @@ module ImportDeclarations =
|> verifyCompileAndRun
|> shouldSucceed

[<FactForNETCOREAPP>]
let ImplementImportedAbstractBaseMethodsFailsIfUsed ()=
FSharp """
module Testing

open System.Text.Json
open System.Text.Json.Serialization

type StringTrimJsonSerializer(o: JsonSerializerOptions) =
inherit JsonConverter<string>()

override this.Read(reader, _, _) =
match reader.TokenType with
| JsonTokenType.String -> reader.GetString().Trim()
| _ -> JsonException("Type is not a string") |> raise

override this.Write(writer, objectToWrite, options) = base.Write(writer, objectToWrite, options)

type SomeType = { AField: string }

let serialize item =
let options = JsonSerializerOptions()
StringTrimJsonSerializer options |> options.Converters.Add
JsonSerializer.Serialize(item, options)

[<EntryPoint>]
let main _ =
{ AField = "a" }
|> serialize
|> ignore
0"""
|> verifyCompile
|> shouldFail
|> withDiagnostics [
(Error 1201, Line 15, Col 59, Line 15, Col 101, "Cannot call an abstract base member: 'Write'")
]


[<FactForNETCOREAPP>]
let ImplementImportedAbstractBaseMethodsFailsIfNotUsed ()=
FSharp """
module Testing

open System.Text.Json
open System.Text.Json.Serialization

type StringTrimJsonSerializer(o: JsonSerializerOptions) =
inherit JsonConverter<string>()
override this.Read(reader, _, _) =
match reader.TokenType with
| JsonTokenType.String -> reader.GetString().Trim()
| _ -> JsonException("Type is not a string") |> raise
override this.Write(writer, objectToWrite, options) = base.Write(writer, objectToWrite, options)

type SomeType = { AField: int }

let serialize item =
let options = JsonSerializerOptions()
StringTrimJsonSerializer options |> options.Converters.Add
JsonSerializer.Serialize(item, options)

[<EntryPoint>]
let main _ =
{ AField = 1 }
|> serialize
|>ignore
0"""
|> verifyCompile
|> shouldFail
|> withDiagnostics [
(Error 1201, Line 13, Col 59, Line 13, Col 101, "Cannot call an abstract base member: 'Write'")
]
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ open Collectons
[<Fact>]
let ``Suggest Namespaces`` () =
FSharp """
open System.Collectons
open System.Lema
"""
|> typecheck
|> shouldFail
|> withSingleDiagnostic (Error 39, Line 2, Col 13, Line 2, Col 23,
"The namespace 'Collectons' is not defined.")
|> withSingleDiagnostic (Error 39, Line 2, Col 13, Line 2, Col 17,
"The namespace 'Lema' is not defined.")

[<Fact>]
let ``Suggest Record Labels`` () =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<DefineConstants Condition="'$(Configuration)'=='debug'">$(DefineConstants);DEBUG</DefineConstants>
<!-- allow testing of static methods in interfaces on .NET 6 -->
<EnablePreviewFeatures>true</EnablePreviewFeatures>
<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
</PropertyGroup>

<PropertyGroup Condition="'$(BUILDING_USING_DOTNET)' == 'true'">
Expand Down Expand Up @@ -228,9 +228,9 @@
<Compile Include="Language\SequenceExpressionTests.fs" />
<Compile Include="Language\StaticClassTests.fs" />
<Compile Include="Language\PrintfFormatTests.fs" />
<Compile Include="Language\InterfaceTests.fs" />
<Compile Include="Language\CopyAndUpdateTests.fs" />
<Compile Include="Language\ConstraintIntersectionTests.fs" />
<Compile Include="Language\InterfaceTests.fs" />
<Compile Include="Language\CopyAndUpdateTests.fs" />
<Compile Include="Language\ConstraintIntersectionTests.fs" />
<Compile Include="Language\BooleanReturningAndReturnTypeDirectedPartialActivePatternTests.fs" />
<Compile Include="ConstraintSolver\PrimitiveConstraints.fs" />
<Compile Include="ConstraintSolver\MemberConstraints.fs" />
Expand Down Expand Up @@ -280,7 +280,7 @@
<Compile Include="CompilerService\RangeModule.fs" />
<Compile Include="CompilerService\LruCache.fs" />
<Compile Include="CompilerService\AsyncLock.fs" />
<Compile Include="CompilerService\AsyncMemoize.fs" />
<Compile Include="CompilerService\AsyncMemoize.fs" />
<Compile Include="Debugger\PortablePdbs.fs" />
<Compile Include="Diagnostics\async.fs" />
<Compile Include="Diagnostics\General.fs" />
Expand Down Expand Up @@ -313,14 +313,12 @@
<Compile Include="FSharpChecker\TransparentCompiler.fs" />
<Compile Include="FSharpChecker\SymbolUse.fs" />
<Compile Include="FSharpChecker\FindReferences.fs" />
<None Include="**\*.cs;**\*.fs;**\*.fsx;**\*.fsi" Exclude="@(Compile)">
<Link>%(RelativeDir)TestSource\%(Filename)%(Extension)</Link>
</None>
</ItemGroup>

<ItemGroup />

<ItemGroup>
<None Include="**\*.cs;**\*.fs;**\*.fsx;**\*.fsi" Exclude="@(Compile)">
<Link>%(RelativeDir)TestSource\%(Filename)%(Extension)</Link>
</None>
<None Include="**\*.bsl">
<Link>%(RelativeDir)\BaseLine\%(Filename)%(Extension)</Link>
</None>
Expand All @@ -331,6 +329,7 @@
<EmbeddedResource Remove="Properties\**" />
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(FSharpSourcesRoot)\Compiler\FSharp.Compiler.Service.fsproj" />
<ProjectReference Include="$(FSharpSourcesRoot)\FSharp.Compiler.Interactive.Settings\FSharp.Compiler.Interactive.Settings.fsproj" />
Expand Down