Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit412e6e6

Browse files
dsymelatkin
authored andcommitted
Fixdotnet#44 - Problems using FSI on a project
commite5f1ec9Author: Don Syme <dsyme@microsoft.com>Date: Tue Jan 20 17:34:33 2015 +0000 fix typocommit80dbab8Author: Don Syme <dsyme@microsoft.com>Date: Tue Jan 20 14:50:12 2015 +0000 Restrict fix fordotnet#44 to F# Interactivecommit1b2f9fcAuthor: Don Syme <dsyme@microsoft.com>Date: Tue Jan 20 14:41:17 2015 +0000Fixdotnet#44 - Problems using FSI on a project
1 parent8de3e85 commit412e6e6

File tree

10 files changed

+80
-18
lines changed

10 files changed

+80
-18
lines changed

‎src/fsharp/build.fs‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5027,17 +5027,26 @@ let TypecheckOneInputEventually
50275027

50285028
// Only add it to the environment if it didn't have a signature
50295029
letm= qualNameOfFile.Range
5030+
5031+
// Add the implementation as to the implementation env
50305032
lettcImplEnv= Tc.AddLocalRootModuleOrNamespace TcResultsSink.NoSink tcGlobals amap m tcImplEnv implFileSigType
5033+
5034+
// Add the implementation as to the signature env (unless it had an explicit signature)
50315035
lettcSigEnv=
50325036
if hadSigthen tcState.tcsTcSigEnv
50335037
else Tc.AddLocalRootModuleOrNamespace TcResultsSink.NoSink tcGlobals amap m tcState.tcsTcSigEnv implFileSigType
50345038

5035-
// Open the prefixPath for fsi.exe
5039+
// Open the prefixPath for fsi.exe(tcImplEnv)
50365040
lettcImplEnv=
50375041
match prefixPathOptwith
5038-
| None-> tcImplEnv
5039-
| Some prefixPath->
5040-
TcOpenDecl tcSink tcGlobals amap m m tcImplEnv prefixPath
5042+
| Some prefixPath-> TcOpenDecl tcSink tcGlobals amap m m tcImplEnv prefixPath
5043+
|_-> tcImplEnv
5044+
5045+
// Open the prefixPath for fsi.exe (tcSigEnv)
5046+
lettcSigEnv=
5047+
match prefixPathOptwith
5048+
| Some prefixPathwhennot hadSig-> TcOpenDecl tcSink tcGlobals amap m m tcSigEnv prefixPath
5049+
|_-> tcSigEnv
50415050

50425051
letallImplementedSigModulTyp= combineModuleOrNamespaceTypeList[] m[implFileSigType; allImplementedSigModulTyp]
50435052

@@ -5050,7 +5059,7 @@ let TypecheckOneInputEventually
50505059
if verbosethen dprintf"done TypecheckOneInputEventually...\n"
50515060

50525061
lettopSigsAndImpls= RootSigsAndImpls(rootSigs,rootImpls,allSigModulTyp,allImplementedSigModulTyp)
5053-
letres=(topAttrs,[implFile], tcEnvAtEnd, tcSigEnv, tcImplEnv,topSigsAndImpls,ccuType)
5062+
letres=(topAttrs,[implFile], tcEnvAtEnd, tcSigEnv, tcImplEnv,topSigsAndImpls,ccuType)
50545063
return res}
50555064

50565065
return(tcEnvAtEnd,topAttrs,mimpls),

‎src/fsharp/tc.fs‎

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -607,12 +607,21 @@ let BuildRootModuleExpr enclosingNamespacePath cpath mexpr =
607607
||> List.foldBack (fun id (cpath, mexpr) -> (parentCompPath cpath, wrapModuleOrNamespaceExprInNamespace id (parentCompPath cpath) mexpr))
608608
|> snd
609609

610-
let ImplicitlyOpenOwnNamespace tcSinkg amap scopem enclosingNamespacePath env =
610+
let ImplicitlyOpenOwnNamespace tcSink(g:TcGlobals) amap scopem(enclosingNamespacePath: Ident list) env =
611611
if isNil enclosingNamespacePath then
612612
env
613613
else
614+
// For F# interactive, skip "FSI_0002" prefixes when determining the path to open implicitly
615+
let enclosingNamespacePathToOpen =
616+
match enclosingNamespacePath with
617+
| p::rest when g.isInteractive &&
618+
p.idText.StartsWith(FsiDynamicModulePrefix,System.StringComparison.Ordinal) &&
619+
p.idText.[FsiDynamicModulePrefix.Length..] |> String.forall System.Char.IsDigit &&
620+
rest.Length > 0 -> rest
621+
| rest -> rest
622+
614623
let ad = env.eAccessRights
615-
match ResolveLongIndentAsModuleOrNamespace amap scopem OpenQualified env.eNameResEnv adenclosingNamespacePath with
624+
match ResolveLongIndentAsModuleOrNamespace amap scopem OpenQualified env.eNameResEnv adenclosingNamespacePathToOpen with
616625
| Result modrefs -> OpenModulesOrNamespaces tcSink g amap scopem false env (List.map p23 modrefs)
617626
| Exception _ -> env
618627

@@ -913,8 +922,8 @@ let ComputeLogicalName (id:Ident) memberFlags =
913922
| (".ctor" | ".cctor") as r -> errorR(Error(FSComp.SR.tcInvalidMemberNameCtor(),id.idRange)); r
914923
| r -> r
915924
| MemberKind.PropertyGetSet -> error(InternalError(FSComp.SR.tcMemberKindPropertyGetSetNotExpected(),id.idRange))
916-
| MemberKind.PropertyGet -> "get_"^id.idText
917-
| MemberKind.PropertySet -> "set_"^id.idText
925+
| MemberKind.PropertyGet -> "get_" +id.idText
926+
| MemberKind.PropertySet -> "set_" +id.idText
918927

919928
/// ValMemberInfoTransient(memberInfo,logicalName,compiledName)
920929
type ValMemberInfoTransient = ValMemberInfoTransient of ValMemberInfo * string * string
@@ -945,7 +954,7 @@ let MakeMemberDataAndMangledNameForMemberVal(g,tcref,isExtrinsic,attrs,optImplSl
945954
let compiledName =
946955
if isExtrinsic then
947956
let tname = tcref.LogicalName
948-
let text = tname^"."^logicalName
957+
let text = tname +"." +logicalName
949958
let text = if memberFlags.MemberKind <> MemberKind.Constructor && memberFlags.MemberKind <> MemberKind.ClassConstructor && not memberFlags.IsInstance then text^".Static" else text
950959
let text = if memberFlags.IsOverrideOrExplicitImpl then text^".Override" else text
951960
text
@@ -4040,8 +4049,8 @@ and TcValSpec cenv env declKind newOk containerInfo memFlagsOpt thisTyOpt tpenv
40404049
thisTy --> (delTy --> cenv.g.unit_ty)
40414050
else
40424051
(delTy --> cenv.g.unit_ty)
4043-
yield reallyGenerateOneMember(ident("add_"^id.idText,id.idRange),valSynInfo,ty,memberFlags)
4044-
yield reallyGenerateOneMember(ident("remove_"^id.idText,id.idRange),valSynInfo,ty,memberFlags) ]
4052+
yield reallyGenerateOneMember(ident("add_" +id.idText,id.idRange),valSynInfo,ty,memberFlags)
4053+
yield reallyGenerateOneMember(ident("remove_" +id.idText,id.idRange),valSynInfo,ty,memberFlags) ]
40454054

40464055

40474056

@@ -4635,7 +4644,7 @@ and TcSimplePats cenv optArgsOK checkCxs ty env (tpenv,names,takenNames:Set<_>)
46354644
// This is a little awkward since it would be nice if this was
46364645
// uniform with the process where we give names to other (more complex)
46374646
// patterns used in argument position, e.g. "let f (D(x)) = ..."
4638-
let id = ident("unitVar"^string takenNames.Count,m)
4647+
let id = ident("unitVar" +string takenNames.Count,m)
46394648
UnifyTypes cenv env m ty cenv.g.unit_ty
46404649
let _,names,takenNames = TcPatBindingName cenv env id ty false None None (ValInline.Optional,permitInferTypars,noArgOrRetAttribs,false,None,true) (names,takenNames)
46414650
[id.idText],(tpenv,names,takenNames)
@@ -6255,7 +6264,7 @@ and TcConstExpr cenv overallTy env m tpenv c =
62556264

62566265
| SynConst.UserNum (s,suffix) ->
62576266
let expr =
6258-
let modName = ("NumericLiteral"^suffix)
6267+
let modName = ("NumericLiteral" +suffix)
62596268
let ad = env.eAccessRights
62606269
match ResolveLongIndentAsModuleOrNamespace cenv.amap m OpenQualified env.eNameResEnv ad [ident (modName,m)] with
62616270
| Result []
@@ -7980,7 +7989,7 @@ and TcItemThen cenv overallTy env tpenv (item,mItem,rest,afterOverloadResolution
79807989
// This is where the constructor expects arguments but is not applied to arguments, hence build a lambda
79817990
nargtys,
79827991
(fun () ->
7983-
let vs,args = argtys |> List.mapi (fun i ty -> mkCompGenLocal mItem ("arg"^string i) ty) |> List.unzip
7992+
let vs,args = argtys |> List.mapi (fun i ty -> mkCompGenLocal mItem ("arg" +string i) ty) |> List.unzip
79847993
let constrApp = mkConstrApp mItem args
79857994
let lam = mkMultiLambda mItem vs (constrApp, tyOfExpr cenv.g constrApp)
79867995
lam)
@@ -8120,7 +8129,7 @@ and TcItemThen cenv overallTy env tpenv (item,mItem,rest,afterOverloadResolution
81208129
let argTys = argTypars |> List.map mkTyparTy
81218130
let retTy = mkTyparTy retTypar
81228131

8123-
let vs,ves = argTys |> List.mapi (fun i ty -> mkCompGenLocal mItem ("arg"^string i) ty) |> List.unzip
8132+
let vs,ves = argTys |> List.mapi (fun i ty -> mkCompGenLocal mItem ("arg" +string i) ty) |> List.unzip
81248133

81258134
let memberFlags = StaticMemberFlags MemberKind.Member
81268135
let logicalCompiledName = ComputeLogicalName id memberFlags
@@ -13213,7 +13222,7 @@ module TcExceptionDeclarations = begin
1321313222
let args = match args with (UnionCaseFields args) -> args | _ -> error(Error(FSComp.SR.tcExplicitTypeSpecificationCannotBeUsedForExceptionConstructors(),m))
1321413223
let ad = env.eAccessRights
1321513224

13216-
let args' = List.mapi (fun i fdef -> TcRecdUnionAndEnumDeclarations.TcAnonFieldDecl cenv env parent tpenv ("Data"^string i) fdef) args
13225+
let args' = List.mapi (fun i fdef -> TcRecdUnionAndEnumDeclarations.TcAnonFieldDecl cenv env parent tpenv ("Data" +string i) fdef) args
1321713226
TcRecdUnionAndEnumDeclarations.ValidateFieldNames(args, args')
1321813227
if not (String.isUpper id.idText) then errorR(NotUpperCaseConstructor(m))
1321913228
let vis,cpath = ComputeAccessAndCompPath env None m vis parent
@@ -15014,12 +15023,14 @@ let rec TcSignatureElement cenv parent endm (env: TcEnv) e : Eventually<TcEnv> =
1501415023
CheckNamespaceModuleOrTypeName cenv.g id
1501515024

1501615025
let enclosingNamespacePath = if isModule then fst (List.frontAndBack longId) else longId
15026+
1501715027
let defs =
1501815028
if isModule then
1501915029
[SynModuleSigDecl.NestedModule(ComponentInfo(attribs,[], [],[snd(List.frontAndBack longId)],xml,false,vis,m),defs,m)]
1502015030
else
1502115031
defs
1502215032
let envinner = LocateEnv cenv.topCcu env enclosingNamespacePath
15033+
1502315034
let envinner = ImplicitlyOpenOwnNamespace cenv.tcSink cenv.g cenv.amap m enclosingNamespacePath envinner
1502415035

1502515036
let! envAtEnd = TcSignatureElements cenv ParentNone m.EndRange envinner xml defs
@@ -15233,7 +15244,7 @@ let rec TcModuleOrNamespaceElement (cenv:cenv) parent scopem env e = // : ((Modu
1523315244

1523415245
| SynModuleDecl.NamespaceFragment(SynModuleOrNamespace(longId,isModule,defs,xml,attribs,vis,m)) ->
1523515246

15236-
if !progress then dprintn ("Typecheck implementation "^textOfLid longId)
15247+
if !progress then dprintn ("Typecheck implementation " +textOfLid longId)
1523715248
let endm = m.EndRange
1523815249

1523915250
do for id in longId do

‎tests/fsharp/core/fsi-reload/a1.fs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespaceProject
2+
3+
typeDU= A| B

‎tests/fsharp/core/fsi-reload/a2.fs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespaceProject
2+
3+
typeB={ Prop:DU}

‎tests/fsharp/core/fsi-reload/b1.fs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespaceProject
2+
3+
typeDU= A| B

‎tests/fsharp/core/fsi-reload/b2.fs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespaceProject
2+
3+
typeB={ Prop:DU}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespaceProject
2+
3+
typeB={ Prop:DU}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Test the case where a2.fs is in the same namespace as a1.fs, and so the namespace is implicitly opened
2+
#load"a1.fs"
3+
#load"a2.fs"
4+
5+
letos= System.IO.File.CreateText"test.ok"in os.Close()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Test the case where b2.fsi/fs is in the same namespace as b1.fs, and so the namespace is implicitly opened
2+
#load"b1.fs"
3+
#load"b2.fsi""b2.fs"
4+
5+
letos= System.IO.File.CreateText"test.ok"in os.Close()

‎tests/fsharp/core/fsi-reload/run.bat‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,23 @@ call %~d0%~p0..\..\..\config.bat
99
"%FSI%"%fsi_flags% --maxerrors:1< test1.ml
1010
ifNOTEXIST test.okgoto SetError
1111

12+
ifexist test.ok (del /f /q test.ok)
13+
"%FSI%"%fsi_flags% --maxerrors:1 load1.fsx
14+
ifNOTEXIST test.okgoto SetError
15+
16+
ifexist test.ok (del /f /q test.ok)
17+
"%FSI%"%fsi_flags% --maxerrors:1 load2.fsx
18+
ifNOTEXIST test.okgoto SetError
19+
20+
REM Check we can also compile, for sanity's sake
21+
"%FSC%" load1.fsx
22+
@if ERRORLEVEL1goto Error
23+
24+
REM Check we can also compile, for sanity's sake
25+
"%FSC%" load2.fsx
26+
@if ERRORLEVEL1goto Error
27+
28+
1229
:Ok
1330
echo Ran fsharp%~f0 ok.
1431
endlocal

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp