Skip to content

Commit e9772de

Browse files
committed
Corrections to ',' and '+' escaping for type names in quotations
1 parent 0676493 commit e9772de

File tree

2 files changed

+5
-20
lines changed

2 files changed

+5
-20
lines changed

src/absil/ilreflect.fs

+1-19
Original file line numberDiff line numberDiff line change
@@ -324,25 +324,7 @@ type cenv =
324324
// [ns] ,name -> ns+name
325325
// [ns;typeA;typeB],name -> ns+typeA+typeB+name
326326
let convTypeRefAux (cenv:cenv) (tref:ILTypeRef) =
327-
328-
// If an inner nested type's name contains a space, the proper encoding is "\+" on both sides - otherwise,
329-
// we use "+"
330-
let rec collectPrefixParts (l : string list) (acc : string list) =
331-
match l with
332-
| h1 :: (h2 :: _ as tl) ->
333-
collectPrefixParts tl
334-
(List.append
335-
acc
336-
[ yield h1
337-
if h1.Contains(" ") || h2.Contains(" ") then
338-
yield "\\+"
339-
else
340-
yield "+"])
341-
| h :: [] -> List.append acc [h]
342-
| _ -> acc
343-
344-
let prefix = collectPrefixParts tref.Enclosing [] |> List.fold (fun (s1 : string) (s2 : string) -> s1 + s2) ""
345-
let qualifiedName = prefix + (if prefix <> "" then (if tref.Name.Contains(" ") then "\\+" else "+") else "") + tref.Name // e.g. Name.Space.Class+NestedClass
327+
let qualifiedName = (String.concat "+" (tref.Enclosing @ [ tref.Name ])).Replace(",", @"\,")
346328
match tref.Scope with
347329
| ILScopeRef.Assembly asmref ->
348330
let assembly =

src/fsharp/FSharp.Core/quotations.fs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1298,8 +1298,11 @@ module Patterns =
12981298
if System.Int32.TryParse(a, &idx) && b = "" then
12991299
st.referencedTypeDefs.[idx]
13001300
else
1301+
// escape commas found in type name, which are not already escaped
1302+
// '\' is not valid in a type name except as an escape character, so logic can be pretty simple
1303+
let escapedTcName = System.Text.RegularExpressions.Regex.Replace(a, @"(?<!\\),", @"\,")
13011304
let assref = decodeAssemblyRef st b
1302-
mkNamedTycon (a,assref)
1305+
mkNamedTycon (escapedTcName, assref)
13031306

13041307
let u_tyconstSpec st =
13051308
let tag = u_byte_as_int st

0 commit comments

Comments
 (0)