@@ -140,7 +140,9 @@ type env =
140
140
/// Are we in a quotation?
141
141
quote : bool
142
142
/// Are we under [<ReflectedDefinition>]?
143
- reflect : bool }
143
+ reflect : bool
144
+ /// Are we in an extern declaration?
145
+ external : bool }
144
146
145
147
let BindTypar env ( tp : Typar ) =
146
148
{ env with
@@ -178,11 +180,12 @@ type cenv =
178
180
mutable usesQuotations : bool
179
181
mutable entryPointGiven: bool }
180
182
181
- let BindVal cenv ( v : Val ) =
183
+ let BindVal cenv env ( v : Val ) =
182
184
//printfn "binding %s..." v.DisplayName
183
185
let alreadyDone = cenv.boundVals.ContainsKey v.Stamp
184
186
cenv.boundVals.[ v.Stamp] <- 1
185
- if not alreadyDone &&
187
+ if not env.external &&
188
+ not alreadyDone &&
186
189
cenv.reportErrors &&
187
190
not v.HasBeenReferenced &&
188
191
not v.IsCompiledAsTopLevel &&
@@ -195,7 +198,7 @@ let BindVal cenv (v:Val) =
195
198
| _ ->
196
199
warning ( Error( FSComp.SR.chkUnusedValue v.DisplayName, v.Range))
197
200
198
- let BindVals cenv vs = List.iter ( BindVal cenv) vs
201
+ let BindVals cenv env vs = List.iter ( BindVal cenv env ) vs
199
202
200
203
//--------------------------------------------------------------------------
201
204
// approx walk of type
@@ -529,7 +532,7 @@ and CheckExpr (cenv:cenv) (env:env) expr (context:ByrefContext) =
529
532
530
533
| Expr.Let ( bind, body,_,_) ->
531
534
CheckBinding cenv env false bind
532
- BindVal cenv bind.Var
535
+ BindVal cenv env bind.Var
533
536
CheckExpr cenv env body context
534
537
535
538
| Expr.Const (_, m, ty) ->
@@ -700,7 +703,7 @@ and CheckExpr (cenv:cenv) (env:env) expr (context:ByrefContext) =
700
703
CheckDecisionTreeTargets cenv env targets context
701
704
702
705
| Expr.LetRec ( binds, e,_,_) ->
703
- BindVals cenv ( valsOfBinds binds)
706
+ BindVals cenv env ( valsOfBinds binds)
704
707
CheckBindings cenv env binds
705
708
CheckExprNoByrefs cenv env e
706
709
@@ -943,7 +946,7 @@ and CheckLambdas isTop (memInfo: ValMemberInfo option) cenv env inlined topValIn
943
946
restArgs |> List.iter ( fun arg -> if isByrefTy cenv.g arg.Type then arg.SetHasBeenReferenced())
944
947
945
948
syntacticArgs |> List.iter ( CheckValSpec cenv env)
946
- syntacticArgs |> List.iter ( BindVal cenv)
949
+ syntacticArgs |> List.iter ( BindVal cenv env )
947
950
948
951
// Trigger a test hook
949
952
match memInfo with
@@ -1014,7 +1017,7 @@ and CheckDecisionTreeTargets cenv env targets context =
1014
1017
targets |> Array.iter ( CheckDecisionTreeTarget cenv env context)
1015
1018
1016
1019
and CheckDecisionTreeTarget cenv env context ( TTarget ( vs , e , _ )) =
1017
- BindVals cenv vs
1020
+ BindVals cenv env vs
1018
1021
vs |> List.iter ( CheckValSpec cenv env)
1019
1022
CheckExpr cenv env e context
1020
1023
@@ -1136,6 +1139,8 @@ and CheckBinding cenv env alwaysCheckNoReraise (TBind(v,bindRhs,_) as bind) =
1136
1139
let isTop = Option.isSome bind.Var.ValReprInfo
1137
1140
//printfn "visiting %s..." v.DisplayName
1138
1141
1142
+ let env = { env with external = env.external || cenv.g.attrib_ DllImportAttribute |> Option.exists ( fun attr -> HasFSharpAttribute cenv.g attr v.Attribs) }
1143
+
1139
1144
// Check that active patterns don't have free type variables in their result
1140
1145
match TryGetActivePatternInfo ( mkLocalValRef v) with
1141
1146
| Some _ apinfo when _ apinfo.ActiveTags.Length > 1 ->
@@ -1669,13 +1674,13 @@ and CheckDefnInModule cenv env x =
1669
1674
match x with
1670
1675
| TMDefRec( isRec, tycons, mspecs, m) ->
1671
1676
CheckNothingAfterEntryPoint cenv m
1672
- if isRec then BindVals cenv ( allValsOfModDef x |> Seq.toList)
1677
+ if isRec then BindVals cenv env ( allValsOfModDef x |> Seq.toList)
1673
1678
CheckEntityDefns cenv env tycons
1674
1679
List.iter ( CheckModuleSpec cenv env) mspecs
1675
1680
| TMDefLet( bind, m) ->
1676
1681
CheckNothingAfterEntryPoint cenv m
1677
1682
CheckModuleBinding cenv env bind
1678
- BindVal cenv bind.Var
1683
+ BindVal cenv env bind.Var
1679
1684
| TMDefDo( e, m) ->
1680
1685
CheckNothingAfterEntryPoint cenv m
1681
1686
CheckNoReraise cenv None e
@@ -1686,7 +1691,7 @@ and CheckDefnInModule cenv env x =
1686
1691
and CheckModuleSpec cenv env x =
1687
1692
match x with
1688
1693
| ModuleOrNamespaceBinding.Binding bind ->
1689
- BindVals cenv ( valsOfBinds [ bind])
1694
+ BindVals cenv env ( valsOfBinds [ bind])
1690
1695
CheckModuleBinding cenv env bind
1691
1696
| ModuleOrNamespaceBinding.Module ( mspec, rhs) ->
1692
1697
CheckEntityDefn cenv env mspec
@@ -1726,7 +1731,8 @@ let CheckTopImpl (g,amap,reportErrors,infoReader,internalsVisibleToPaths,viewCcu
1726
1731
boundTyparNames=[]
1727
1732
argVals = ValMap.Empty
1728
1733
boundTypars= TyparMap.Empty
1729
- reflect= false }
1734
+ reflect= false
1735
+ external= false }
1730
1736
1731
1737
CheckModuleExpr cenv env mexpr
1732
1738
CheckAttribs cenv env extraAttribs
0 commit comments