From 4267370bb550140dad7ee622a90f6cdc0fc888da Mon Sep 17 00:00:00 2001 From: KevinRansom Date: Sun, 22 Feb 2015 11:38:18 -0800 Subject: [PATCH] Fixes #9, Internal error in FSI: FS0192: binding null type in envBindTypeRef #9 Fixes #10, internal error: binding null type in envBindTypeRef Both issues were caused by the same underlying issue. RefEmit automagically applies escaping to names that contain a ',' So ``,`` becomes ``\,``. When we tried to create a ref to a nested type we didn't add the ',' escaping so we couldnot bind to the created type. The fix is very straightforward, change BasicQualifiedName to correctly escape names with comma's. --- src/absil/il.fs | 4 +- .../backtickmoduleandtypenames.fsx | 79 +++++++++++++++++++ .../IdentifiersAndKeywords/env.lst | 4 + 3 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 tests/fsharpqa/Source/Conformance/LexicalAnalysis/IdentifiersAndKeywords/backtickmoduleandtypenames.fsx diff --git a/src/absil/il.fs b/src/absil/il.fs index 8abf818b4..7ff1289fe 100644 --- a/src/absil/il.fs +++ b/src/absil/il.fs @@ -678,8 +678,8 @@ type ILTypeRef = member tref.FullName = String.concat "." (tref.Enclosing @ [tref.Name]) - member tref.BasicQualifiedName = - String.concat "+" (tref.Enclosing @ [ tref.Name ]) + member tref.BasicQualifiedName = + (String.concat "+" (tref.Enclosing @ [ tref.Name ] )).Replace(",", @"\,") member tref.AddQualifiedNameExtensionWithNoShortPrimaryAssembly(basic) = let sco = tref.Scope.QualifiedNameWithNoShortPrimaryAssembly diff --git a/tests/fsharpqa/Source/Conformance/LexicalAnalysis/IdentifiersAndKeywords/backtickmoduleandtypenames.fsx b/tests/fsharpqa/Source/Conformance/LexicalAnalysis/IdentifiersAndKeywords/backtickmoduleandtypenames.fsx new file mode 100644 index 000000000..b578bcded --- /dev/null +++ b/tests/fsharpqa/Source/Conformance/LexicalAnalysis/IdentifiersAndKeywords/backtickmoduleandtypenames.fsx @@ -0,0 +1,79 @@ +// +open System +open System.Reflection + +open Microsoft.FSharp.Quotations +open Microsoft.FSharp.Quotations.Patterns +open Microsoft.FSharp.Quotations.DerivedPatterns + +let failures = ref false +let report_failure () = + stderr.WriteLine " NO"; failures := true +let test s b = stderr.Write(s:string); if b then stderr.WriteLine " OK" else report_failure() + +(*--------------------*) + +// Test cases for Github Issue # 10 module cannot contain , + +// Comma in module name +module ``,`` = + let x = 3 + +// Lots of comma's in module name +module ``,,,,,,,,,,,`` = + let x = 5 + +// Lots of comma's and other characters in module name +module ``One, 2, Three, 4, Five`` = + let x = 7 + +// Nested modules with commas +module ``Nested modules with commas`` = + module ``One, `` = + module ``Two, `` = + module ``Three, `` = + let x = 9 + +module ``Comma in type name`` = + type ``,`` = + static member x = 13 + +// Lots of comma's in type name +module ``Lots of comma's in type name`` = + type ``,,,,,,,`` = + static member x = 15 + +// Lots of comma's and other characters in type name +module ``Lots of comma's and other characters in type name`` = + type ``One, 2, Three, 4, Five`` = + static member x = 17 + +do + let eval expr value = if (expr) = value then true else false + + test "Comma in module name" (eval ``,``.x 3) + test "Lots of comma's in module name" (eval ``,,,,,,,,,,,``.x 5) + test "Lots of comma's and other characters in module name" (eval ``One, 2, Three, 4, Five``.x 7) + test "Nested modules with commas" (eval ``Nested modules with commas``.``One, ``.``Two, ``.``Three, ``.x 9) + + test "Comma in type name" (eval ``Comma in type name``.``,``.x 13) + test "Lots of comma's in type name" (eval ``Lots of comma's in type name``.``,,,,,,,``.x 15) + test "Lots of comma's and other characters in type name" (eval ``Lots of comma's and other characters in type name``.``One, 2, Three, 4, Five``.x 17) + + let eval expr value = (match expr with | PropertyGet (a, b, c) -> (if (b.GetGetMethod(true) :> MethodBase).Invoke(null, null) :?>int = value then true else false) | _ -> false) + + test "Comma in module name from quotation" (eval <@@ ``,``.x @@> 3) + test "Lots of comma's in module name from quotation" (eval <@@ ``,,,,,,,,,,,``.x @@> 5) + test "Lots of comma's and other characters in module name from quotation" (eval <@@ ``One, 2, Three, 4, Five``.x @@> 7) + test "Nested modules with commas from quotation" (eval <@@ ``Nested modules with commas``.``One, ``.``Two, ``.``Three, ``.x @@> 9) + + test "Comma in type name from quotation" (eval <@@ ``Comma in type name``.``,``.x @@> 13) + test "Lots of comma's in type name from quotation" (eval <@@ ``Lots of comma's in type name``.``,,,,,,,``.x @@> 15) + test "Lots of comma's and other characters in type name from quotation" (eval <@@ ``Lots of comma's and other characters in type name``.``One, 2, Three, 4, Five``.x @@> 17) + +let aa = + if !failures then (stdout.WriteLine "Test Failed"; exit 1) + +do (stdout.WriteLine "Test Passed"; + System.IO.File.WriteAllText("test.ok","ok"); + exit 0) diff --git a/tests/fsharpqa/Source/Conformance/LexicalAnalysis/IdentifiersAndKeywords/env.lst b/tests/fsharpqa/Source/Conformance/LexicalAnalysis/IdentifiersAndKeywords/env.lst index 8c41b6933..3391bf360 100644 --- a/tests/fsharpqa/Source/Conformance/LexicalAnalysis/IdentifiersAndKeywords/env.lst +++ b/tests/fsharpqa/Source/Conformance/LexicalAnalysis/IdentifiersAndKeywords/env.lst @@ -9,6 +9,10 @@ SOURCE=E_KeywordIdent01.fs # E_KeywordIdent01.fs SOURCE=E_ValidIdentifier03.fs SCFLAGS="--test:ErrorRanges" # E_ValidIdentifier03.fs SOURCE=E_ValidIdentifier04.fs # E_ValidIdentifier04.fs + + SOURCE=backtickmoduleandtypenames.fsx # backtickmoduleandtypenames.fsx + SOURCE=backtickmoduleandtypenames.fsx FSIMODE=EXEC COMPILE_ONLY=1 # backtickmoduleandtypenames.fsx FSIMODE=EXEC COMPILE_ONLY=1 + SOURCE=StructNotAllowDoKeyword.fs # StructNotAllowDoKeyword.fs SOURCE=E_MissingQualification.fs SCFLAGS="--test:ErrorRanges" # E_MissingQualification.fs -- GitLab