@@ -140,7 +140,9 @@ type env =
140140/// Are we in a quotation?
141141 quote: bool
142142/// Are we under [<ReflectedDefinition>]?
143- reflect: bool }
143+ reflect: bool
144+ /// Are we in an extern declaration?
145+ external: bool }
144146
145147let BindTypar env ( tp : Typar ) =
146148{ envwith
@@ -178,11 +180,12 @@ type cenv =
178180mutable usesQuotations: bool
179181mutable entryPointGiven: bool }
180182
181- let BindVal cenv ( v : Val ) =
183+ let BindVal cenvenv ( v : Val ) =
182184//printfn "binding %s..." v.DisplayName
183185let alreadyDone = cenv.boundVals.ContainsKey v.Stamp
184186 cenv.boundVals.[ v.Stamp] <- 1
185- if not alreadyDone&&
187+ if not env.external&&
188+ not alreadyDone&&
186189 cenv.reportErrors&&
187190not v.HasBeenReferenced&&
188191not v.IsCompiledAsTopLevel&&
@@ -195,7 +198,7 @@ let BindVal cenv (v:Val) =
195198| _ ->
196199 warning( Error( FSComp.SR.chkUnusedValue v.DisplayName, v.Range))
197200
198- let BindVals cenv vs = List.iter( BindVal cenv) vs
201+ let BindVals cenvenv vs = List.iter( BindVal cenv env ) vs
199202
200203//--------------------------------------------------------------------------
201204// approx walk of type
@@ -529,7 +532,7 @@ and CheckExpr (cenv:cenv) (env:env) expr (context:ByrefContext) =
529532
530533| Expr.Let( bind, body,_,_) ->
531534 CheckBinding cenv envfalse bind
532- BindVal cenv bind.Var
535+ BindVal cenvenv bind.Var
533536 CheckExpr cenv env body context
534537
535538| Expr.Const(_, m, ty) ->
@@ -700,7 +703,7 @@ and CheckExpr (cenv:cenv) (env:env) expr (context:ByrefContext) =
700703 CheckDecisionTreeTargets cenv env targets context
701704
702705| Expr.LetRec( binds, e,_,_) ->
703- BindVals cenv( valsOfBinds binds)
706+ BindVals cenvenv ( valsOfBinds binds)
704707 CheckBindings cenv env binds
705708 CheckExprNoByrefs cenv env e
706709
@@ -943,7 +946,7 @@ and CheckLambdas isTop (memInfo: ValMemberInfo option) cenv env inlined topValIn
943946 restArgs|> List.iter( fun arg -> if isByrefTy cenv.g arg.Typethen arg.SetHasBeenReferenced())
944947
945948 syntacticArgs|> List.iter( CheckValSpec cenv env)
946- syntacticArgs|> List.iter( BindVal cenv)
949+ syntacticArgs|> List.iter( BindVal cenv env )
947950
948951// Trigger a test hook
949952match memInfowith
@@ -1014,7 +1017,7 @@ and CheckDecisionTreeTargets cenv env targets context =
10141017 targets|> Array.iter( CheckDecisionTreeTarget cenv env context)
10151018
10161019and CheckDecisionTreeTarget cenv env context ( TTarget ( vs , e , _ )) =
1017- BindVals cenv vs
1020+ BindVals cenvenv vs
10181021 vs|> List.iter( CheckValSpec cenv env)
10191022 CheckExpr cenv env e context
10201023
@@ -1136,6 +1139,8 @@ and CheckBinding cenv env alwaysCheckNoReraise (TBind(v,bindRhs,_) as bind) =
11361139let isTop = Option.isSome bind.Var.ValReprInfo
11371140//printfn "visiting %s..." v.DisplayName
11381141
1142+ let env = { envwith external= env.external|| cenv.g.attrib_ DllImportAttribute|> Option.exists( fun attr -> HasFSharpAttribute cenv.g attr v.Attribs) }
1143+
11391144// Check that active patterns don't have free type variables in their result
11401145match TryGetActivePatternInfo( mkLocalValRef v) with
11411146| Some_ apinfowhen _ apinfo.ActiveTags.Length> 1 ->
@@ -1669,13 +1674,13 @@ and CheckDefnInModule cenv env x =
16691674match xwith
16701675| TMDefRec( isRec, tycons, mspecs, m) ->
16711676 CheckNothingAfterEntryPoint cenv m
1672- if isRecthen BindVals cenv( allValsOfModDef x|> Seq.toList)
1677+ if isRecthen BindVals cenvenv ( allValsOfModDef x|> Seq.toList)
16731678 CheckEntityDefns cenv env tycons
16741679 List.iter( CheckModuleSpec cenv env) mspecs
16751680| TMDefLet( bind, m) ->
16761681 CheckNothingAfterEntryPoint cenv m
16771682 CheckModuleBinding cenv env bind
1678- BindVal cenv bind.Var
1683+ BindVal cenvenv bind.Var
16791684| TMDefDo( e, m) ->
16801685 CheckNothingAfterEntryPoint cenv m
16811686 CheckNoReraise cenv None e
@@ -1686,7 +1691,7 @@ and CheckDefnInModule cenv env x =
16861691and CheckModuleSpec cenv env x =
16871692match xwith
16881693| ModuleOrNamespaceBinding.Binding bind->
1689- BindVals cenv( valsOfBinds[ bind])
1694+ BindVals cenvenv ( valsOfBinds[ bind])
16901695 CheckModuleBinding cenv env bind
16911696| ModuleOrNamespaceBinding.Module( mspec, rhs) ->
16921697 CheckEntityDefn cenv env mspec
@@ -1726,7 +1731,8 @@ let CheckTopImpl (g,amap,reportErrors,infoReader,internalsVisibleToPaths,viewCcu
17261731 boundTyparNames=[]
17271732 argVals= ValMap.Empty
17281733 boundTypars= TyparMap.Empty
1729- reflect= false }
1734+ reflect= false
1735+ external= false }
17301736
17311737 CheckModuleExpr cenv env mexpr
17321738 CheckAttribs cenv env extraAttribs