Skip to content

Commit c5fb101

Browse files
dsymeKevinRansom
authored andcommitted
Fix 631
1 parent 2a3a19b commit c5fb101

File tree

7 files changed

+47
-6
lines changed

7 files changed

+47
-6
lines changed

src/fsharp/TastOps.fs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,14 @@ let emptyTyparInst = ([] : TyparInst)
8282
type Remap =
8383
{ tpinst : TyparInst;
8484
valRemap: ValRemap;
85-
tyconRefRemap : TyconRefRemap }
85+
tyconRefRemap : TyconRefRemap;
86+
removeTraitSolutions: bool }
8687

8788
let emptyRemap =
8889
{ tpinst = emptyTyparInst;
8990
tyconRefRemap = emptyTyconRefRemap;
90-
valRemap = ValMap.Empty }
91+
valRemap = ValMap.Empty;
92+
removeTraitSolutions = false }
9193

9294
type Remap with
9395
static member Empty = emptyRemap
@@ -228,6 +230,7 @@ and remapTraitAux tyenv (TTrait(typs,nm,mf,argtys,rty,slnCell)) =
228230
let slnCell =
229231
match !slnCell with
230232
| None -> None
233+
| _ when tyenv.removeTraitSolutions -> None
231234
| Some sln ->
232235
let sln =
233236
match sln with
@@ -343,7 +346,8 @@ let remapSlotSig remapAttrib tyenv (TSlotSig(nm,typ, ctps,methTypars,paraml, rty
343346
let mkInstRemap tpinst =
344347
{ tyconRefRemap = emptyTyconRefRemap;
345348
tpinst = tpinst;
346-
valRemap = ValMap.Empty }
349+
valRemap = ValMap.Empty;
350+
removeTraitSolutions = false }
347351

348352
// entry points for "typar -> TType" instantiation
349353
let instType tpinst x = if List.isEmpty tpinst then x else remapTypeAux (mkInstRemap tpinst) x
@@ -1264,6 +1268,8 @@ let tryRescopeEntity viewedCcu (entity:Entity) : EntityRef option =
12641268
let tryRescopeVal viewedCcu (entityRemap:Remap) (vspec:Val) : ValRef option =
12651269
match vspec.PublicPath with
12661270
| Some (ValPubPath(p,fullLinkageKey)) ->
1271+
// The type information in the val linkage doesn't need to keep any information to trait solutions.
1272+
let entityRemap = { entityRemap with removeTraitSolutions = true }
12671273
let fullLinkageKey = remapValLinkage entityRemap fullLinkageKey
12681274
let vref =
12691275
// This compensates for the somewhat poor design decision in the F# compiler and metadata where
@@ -3482,7 +3488,8 @@ let addValRemap v v' tmenv =
34823488
let mkRepackageRemapping mrpi =
34833489
{ valRemap = ValMap.OfList (mrpi.mrpiVals |> List.map (fun (vref,x) -> vref.Deref, x));
34843490
tpinst = emptyTyparInst;
3485-
tyconRefRemap = TyconRefMap.OfList mrpi.mrpiEntities }
3491+
tyconRefRemap = TyconRefMap.OfList mrpi.mrpiEntities
3492+
removeTraitSolutions = false }
34863493

34873494
//--------------------------------------------------------------------------
34883495
// Compute instances of the above for mty -> mty

src/fsharp/TastOps.fsi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,8 @@ type ValRemap = ValMap<ValRef>
311311
type Remap =
312312
{ tpinst : TyparInst;
313313
valRemap: ValRemap;
314-
tyconRefRemap : TyconRefRemap }
314+
tyconRefRemap : TyconRefRemap;
315+
removeTraitSolutions: bool }
315316

316317
static member Empty : Remap
317318

tests/fsharp/single-neg-test.bat

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,23 @@ if exist "%testname%b.ml" (set sources=%sources% %testname%b.ml)
4040
if exist "%testname%b.fs" (set sources=%sources% %testname%b.fs)
4141
if exist "helloWorldProvider.dll" (set sources=%sources% -r:helloWorldProvider.dll)
4242

43+
if exist "%testname%-pre.fs" (
44+
echo set sources=%sources% -r:%testname%-pre.dll
45+
set sources=%sources% -r:%testname%-pre.dll
46+
)
47+
4348
REM check negative tests for bootstrapped fsc.exe due to line-ending differences
4449
if "%FSC:fscp=X%" == "%FSC%" (
4550

51+
if exist "%testname%-pre.fs" (
52+
echo "sources=%sources%"
53+
"%FSC%" %fsc_flags% -a -o:%testname%-pre.dll "%testname%-pre.fs"
54+
@if ERRORLEVEL 1 (
55+
set ERRORMSG=%ERRORMSG% FSC failed for precursor library code for %sources%;
56+
goto SetError
57+
)
58+
)
59+
4660
echo Negative typechecker testing: %testname%
4761
echo "%FSC%" %fsc_flags% --vserrors --warnaserror --nologo --maxerrors:10000 -a -o:%testname%.dll %sources%
4862
"%FSC%" %fsc_flags% --vserrors --warnaserror --nologo --maxerrors:10000 -a -o:%testname%.dll %sources% 2> %testname%.err

tests/fsharp/typecheck/sigs/build.bat

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ setlocal
55
REM Configure the sample, i.e. where to find the F# compiler and C# compiler.
66
call %~d0%~p0..\..\..\config.bat
77

8+
call ..\..\single-neg-test.bat neg94
9+
@if ERRORLEVEL 1 goto Error
10+
811
"%FSC%" %fsc_flags% --target:exe -o:pos22.exe pos22.fs
912
@if ERRORLEVEL 1 goto Error
1013

@@ -338,7 +341,6 @@ call ..\..\single-neg-test.bat neg42
338341
"%PEVERIFY%" pos03a.dll
339342
@if ERRORLEVEL 1 goto Error
340343

341-
342344
call ..\..\single-neg-test.bat neg34
343345
@if ERRORLEVEL 1 goto Error
344346

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace Neg94Pre
2+
3+
type Class1() =
4+
static member inline ($) (r:'R, _) = fun (x:'T) -> ((^R) : (static member method2: ^T -> ^R) x)
5+
static member inline method1 x = Unchecked.defaultof<'r> $ Class1()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
neg94.fs(6,12,6,21): typecheck error FS0039: The value or constructor 'undefined' is not defined
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace Neg94
2+
3+
module Repro1 =
4+
let v = Neg94Pre.Class1()
5+
6+
let v2 = undefined
7+
// We're expecting the compile of this file to fail, but the point is that the
8+
// reference of neg94-pre.dll shouldn't give extra warnings about bad definitions.
9+
// See https://github.com/Microsoft/visualfsharp/issues/631
10+

0 commit comments

Comments
 (0)