From d80118552719cf326f9b340cd8eab3a6715ee1ec Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Mon, 19 Sep 2016 15:01:06 +0200 Subject: [PATCH 1/2] Repro case for #1548 --- tests/fsharpqa/Source/Warnings/Repro1548.fs | 9 +++++++++ tests/fsharpqa/Source/Warnings/env.lst | 1 + 2 files changed, 10 insertions(+) create mode 100644 tests/fsharpqa/Source/Warnings/Repro1548.fs diff --git a/tests/fsharpqa/Source/Warnings/Repro1548.fs b/tests/fsharpqa/Source/Warnings/Repro1548.fs new file mode 100644 index 00000000000..b70d42f5c3a --- /dev/null +++ b/tests/fsharpqa/Source/Warnings/Repro1548.fs @@ -0,0 +1,9 @@ +// #Warnings +//This expression was expected to have type +//The '!' operator is used to dereference a ref cell. Consider using 'not expr' here. + +type E() = + inherit B.Type() + member x.Y() = () + +exit 0 \ No newline at end of file diff --git a/tests/fsharpqa/Source/Warnings/env.lst b/tests/fsharpqa/Source/Warnings/env.lst index 322ed3d77ea..23f0d07ff31 100644 --- a/tests/fsharpqa/Source/Warnings/env.lst +++ b/tests/fsharpqa/Source/Warnings/env.lst @@ -29,3 +29,4 @@ SOURCE=RuntimeTypeTestInPattern.fs # RuntimeTypeTestInPattern.fs SOURCE=RuntimeTypeTestInPattern2.fs # RuntimeTypeTestInPattern2.fs SOURCE=WarnIfExpressionResultUnused.fs # WarnIfExpressionResultUnused.fs + SOURCE=Repro1548.fs SCFLAGS="--r:Repro1548.dll" # Repro1548.fs From e4a5da61e44717e064e3bbf890ee822b45bbf973 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Mon, 19 Sep 2016 17:00:11 +0200 Subject: [PATCH 2/2] Fixes suggestions in #1548 --- src/fsharp/NameResolution.fs | 28 ++++++++++++------- tests/fsharp/typecheck/sigs/neg15.bsl | 12 ++++---- tests/fsharp/typecheck/sigs/neg17.bsl | 12 ++++---- tests/fsharpqa/Source/Warnings/Repro1548.dll | Bin 0 -> 6144 bytes tests/fsharpqa/Source/Warnings/Repro1548.fs | 5 ++-- tests/fsharpqa/Source/Warnings/env.lst | 2 +- 6 files changed, 34 insertions(+), 25 deletions(-) create mode 100644 tests/fsharpqa/Source/Warnings/Repro1548.dll diff --git a/src/fsharp/NameResolution.fs b/src/fsharp/NameResolution.fs index 5d6a480a3f0..64b68750844 100644 --- a/src/fsharp/NameResolution.fs +++ b/src/fsharp/NameResolution.fs @@ -2035,9 +2035,13 @@ let rec ResolveExprLongIdentInModuleOrNamespace (ncenv:NameResolver) nenv (typeN match tyconSearch +++ moduleSearch +++ unionSearch with | Result [] -> let predictedPossibleTypes = - modref.ModuleOrNamespaceType.AllEntities - |> Seq.map (fun e -> e.DisplayName) - |> Set.ofSeq + match ad with + | AccessibleFrom _ -> + modref.ModuleOrNamespaceType.AllEntities + |> Seq.filter (fun e -> IsEntityAccessible ncenv.amap m ad (modref.NestedTyconRef e)) + |> Seq.map (fun e -> e.DisplayName) + |> Set.ofSeq + | _ -> Set.empty raze (UndefinedName(depth,FSComp.SR.undefinedNameValueConstructorNamespaceOrType,id,predictedPossibleTypes)) | results -> AtMostOneResult id.idRange results @@ -2413,13 +2417,17 @@ let ResolveTypeLongIdentInTyconRef sink (ncenv:NameResolver) nenv typeNameResInf tcref /// Create an UndefinedName error with details -let SuggestTypeLongIdentInModuleOrNamespace depth (modref:ModuleOrNamespaceRef) (id:Ident) = +let SuggestTypeLongIdentInModuleOrNamespace depth (modref:ModuleOrNamespaceRef) amap ad m (id:Ident) = let predictedPossibleTypes = - modref.ModuleOrNamespaceType.AllEntities - |> Seq.map (fun e -> e.DisplayName) - |> Set.ofSeq - - let errorTextF s = FSComp.SR.undefinedNameTypeIn(s,fullDisplayTextOfModRef modref) + match ad with + | AccessibleFrom _ -> + modref.ModuleOrNamespaceType.AllEntities + |> Seq.filter (fun e -> IsEntityAccessible amap m ad (modref.NestedTyconRef e)) + |> Seq.map (fun e -> e.DisplayName) + |> Set.ofSeq + | _ -> Set.empty + + let errorTextF s = FSComp.SR.undefinedNameTypeIn(s,fullDisplayTextOfModRef modref) UndefinedName(depth,errorTextF,id,predictedPossibleTypes) /// Resolve a long identifier representing a type in a module or namespace @@ -2431,7 +2439,7 @@ let rec private ResolveTypeLongIdentInModuleOrNamespace (ncenv:NameResolver) (ty let tcrefs = LookupTypeNameInEntityMaybeHaveArity (ncenv.amap, id.idRange, ad, id.idText, typeNameResInfo.StaticArgsInfo, modref) match tcrefs with | _ :: _ -> tcrefs |> CollectResults (fun tcref -> success(resInfo,tcref)) - | [] -> raze (SuggestTypeLongIdentInModuleOrNamespace depth modref id) + | [] -> raze (SuggestTypeLongIdentInModuleOrNamespace depth modref ncenv.amap ad m id) | id::rest -> let m = unionRanges m id.idRange let modulSearch = diff --git a/tests/fsharp/typecheck/sigs/neg15.bsl b/tests/fsharp/typecheck/sigs/neg15.bsl index 06ca079c08d..d57289e5364 100644 --- a/tests/fsharp/typecheck/sigs/neg15.bsl +++ b/tests/fsharp/typecheck/sigs/neg15.bsl @@ -37,11 +37,11 @@ Maybe you want one of the following: InternalRecordType - PrivateUnionType + PublicRecordType - PrivateRecordType + Type - PublicRecordType + UnionTypeWithPrivateRepresentation neg15.fs(128,31,128,61): typecheck error FS0072: Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved. @@ -53,11 +53,11 @@ Maybe you want one of the following: InternalRecordType - PrivateUnionType + PublicRecordType - PrivateRecordType + Type - PublicRecordType + UnionTypeWithPrivateRepresentation neg15.fs(141,30,141,60): typecheck error FS0072: Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved. diff --git a/tests/fsharp/typecheck/sigs/neg17.bsl b/tests/fsharp/typecheck/sigs/neg17.bsl index a37d7abf981..2b55f59a8f3 100644 --- a/tests/fsharp/typecheck/sigs/neg17.bsl +++ b/tests/fsharp/typecheck/sigs/neg17.bsl @@ -31,9 +31,9 @@ Maybe you want one of the following: InternalUnionType - PrivateUnionType + InternalRecordType - PrivateRecordType + Type neg17b.fs(29,31,29,61): typecheck error FS0072: Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved. @@ -49,9 +49,9 @@ Maybe you want one of the following: InternalRecordType - PrivateRecordType + Type - PrivateUnionType + InternalUnionType neg17b.fs(43,30,43,60): typecheck error FS0072: Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved. @@ -65,8 +65,8 @@ Maybe you want one of the following: InternalRecordType - PrivateRecordType + Type - PrivateUnionType + InternalUnionType neg17b.fs(54,20,54,50): typecheck error FS0072: Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved. diff --git a/tests/fsharpqa/Source/Warnings/Repro1548.dll b/tests/fsharpqa/Source/Warnings/Repro1548.dll new file mode 100644 index 0000000000000000000000000000000000000000..c8556e567872a8b194ef4d24c7e293aba0bc53cc GIT binary patch literal 6144 zcmeHLU2Ggz6+UAuabglDCc8;VSv8*Bo!v|` zJG0Ep2AoLX67k<6;0>t)2_dSeFL|g$1wsluAYS@LC6GWw2oP_81S$g5@SQWev%6k9 zLA;V{-!u2zd;ZUzbMNf(i(jW05yjE(-6MJ%Pi}Jp?+@0oJhJbHBlOnbJ7aIFGw+NQ zu2{a_@Z6eb)b+CAIBuYqOxgFh3mtpV|(9HL-1jeoU`sJl`v0S!|ob zfa9?fy{pZ^`iy7VE(qCHT197BA4KnJb42r9s0^RuxT3Lb8YQTq!`A`Cg(uN|@e!iQ zD7fL={ooUtJ4%$+K1@$g8hs-^pa1B*YDs5XugzqpGSgGj*~2U~K{nv4uzmb9q0gtV zImh#XXE`;WDdu1chhY3do^lv-O2t^z&)aSZI5&t=CwCJKLJs{?P0Iv^ zyU^jL$b!KVQuZ12QRgUxaY)ij^aA|Zqm)WgO)Ud{Q>_Eu68JNLe-QY-z&#qT9u&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U)uo}XGP&;oDmf7`EtXJ8Etyh-+TeC=a1>`lY}@dN0){@S6s{afyZJPy z1V?J(1JP*_W(g^R7^1)N6$Mk>w?(Gl^GBl?=QXaAv?Q)>2~j-00N$v{3U4sHtfVjy{C2Az~`<3tz|<}Y+&Zi z1&9R+Tnv;Nz((Idln%rACc=aJ-=<-N-XSn+2@RWxU45JoEQ-hQ(8w) zOSV|n*3)6cO>#TrvqS83CokF%8@rwT6)$&$s60Y1K+bt(hX;j^i%3{Vcq!a?oG3UK z!@?*M$W9G}+L^0Q-)LK(CW=OJ4TrMO8y4B4k2iYvW@lZIKHhHa&l>|4Xw)fIy(Nuk zNX>V>!r@EasZo8eySfzBl%5*VTX&!z{>5YQM3Q%drnL26-+_f&wirFWsM!o*4Q>VZEm4BsQz5d!9 z(oPSkz(u$8a#8LR#pqp_zis;ol6E*nWBjrAN_md=L7duVdDxHPT_D328p$ zxbmf)#Wy2=d4`>RXTG+cjnqUN>1Tv~1u|W#P!r#q!2@+X1`P_|r!MTO!yX4b@}mdr zKFY^mq(6sMA2Qkh2B_LrD;;wdE`*SO>SwcqY1RX@J&&v~C{e zJB3QEz-=M}2I9z;H$cZ$)#wWBqD|&>x`lY_bPzGk5-!H{r0D9%DTw_Q$gPVXSEDGP yE`VMklI&kQ8=b5ZO%NX?p#%qfHYmH}Lv))79=3J_^zb*s)no06htL0~2>b`&bTSkG literal 0 HcmV?d00001 diff --git a/tests/fsharpqa/Source/Warnings/Repro1548.fs b/tests/fsharpqa/Source/Warnings/Repro1548.fs index b70d42f5c3a..db7f9765368 100644 --- a/tests/fsharpqa/Source/Warnings/Repro1548.fs +++ b/tests/fsharpqa/Source/Warnings/Repro1548.fs @@ -1,6 +1,7 @@ // #Warnings -//This expression was expected to have type -//The '!' operator is used to dereference a ref cell. Consider using 'not expr' here. +//The type 'Type' is not defined in 'B'. +//Maybe you want one of the following: +//PublicType type E() = inherit B.Type() diff --git a/tests/fsharpqa/Source/Warnings/env.lst b/tests/fsharpqa/Source/Warnings/env.lst index 23f0d07ff31..b26c21de72f 100644 --- a/tests/fsharpqa/Source/Warnings/env.lst +++ b/tests/fsharpqa/Source/Warnings/env.lst @@ -29,4 +29,4 @@ SOURCE=RuntimeTypeTestInPattern.fs # RuntimeTypeTestInPattern.fs SOURCE=RuntimeTypeTestInPattern2.fs # RuntimeTypeTestInPattern2.fs SOURCE=WarnIfExpressionResultUnused.fs # WarnIfExpressionResultUnused.fs - SOURCE=Repro1548.fs SCFLAGS="--r:Repro1548.dll" # Repro1548.fs + SOURCE=Repro1548.fs SCFLAGS="-r:Repro1548.dll" # Repro1548.fs