Skip to content

Commit 529cc6f

Browse files
Vasily KirichenkoVasily Kirichenko
authored andcommitted
Apply feedback
1 parent 223d313 commit 529cc6f

12 files changed

+30
-27
lines changed

src/fsharp/Optimizer.fs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2304,8 +2304,17 @@ and DevirtualizeApplication cenv env (vref:ValRef) ty tyargs args m =
23042304
let transformedExpr = wrap (MakeApplicationAndBetaReduce cenv.g (exprForValRef m vref,vref.Type,(if isNil tyargs then [] else [tyargs]),args,m))
23052305
OptimizeExpr cenv env transformedExpr
23062306

2307-
2308-
2307+
2308+
and GetNameFromTypeName tcGlobals m typeName =
2309+
match stripTyEqns tcGlobals typeName with
2310+
| TType_app (tcref, _) -> tcref.CompiledRepresentationForNamedType.FullName
2311+
| TType_forall _ -> errorR(Error(FSComp.SR.expressionHasNoName(), m)); ""
2312+
| TType_tuple _ -> errorR(Error(FSComp.SR.expressionHasNoName(), m)); ""
2313+
| TType_fun _ -> errorR(Error(FSComp.SR.expressionHasNoName(), m)); ""
2314+
| TType_ucase _ -> errorR(Error(FSComp.SR.expressionHasNoName(), m)); ""
2315+
| TType_var tp -> tp.DisplayName
2316+
| TType_measure ms -> sprintf "%A" ms
2317+
23092318
and TryDevirtualizeApplication cenv env (f,tyargs,args,m) =
23102319
match f,tyargs,args with
23112320

@@ -2514,17 +2523,8 @@ and TryDevirtualizeApplication cenv env (f,tyargs,args,m) =
25142523
// Analyze the name of the given type and rewrite AST to constant string expression with the name
25152524
| Expr.Val(vref,_,_),_,_ when valRefEq cenv.g vref cenv.g.typenameof_vref ->
25162525
match tyargs with
2517-
| (typeName:TType):: _ ->
2518-
let name =
2519-
match typeName with
2520-
| TType_forall (_tps,ty) -> ty.ToString()
2521-
| TType_app (tcref, _) -> tcref.CompiledRepresentationForNamedType.FullName
2522-
| TType_tuple tinst -> "(" + String.concat "," (List.map string tinst) + ")"
2523-
| TType_fun (d,r) -> "(" + string d + " -> " + string r + ")"
2524-
| TType_ucase (uc,_) -> uc.CaseName
2525-
| TType_var tp -> tp.DisplayName
2526-
| TType_measure ms -> sprintf "%A" ms
2527-
2526+
| typeName:: _ ->
2527+
let name = GetNameFromTypeName cenv.g m typeName
25282528
Some(Expr.Const(Const.String name, m, cenv.g.string_ty),
25292529
{ TotalSize = 1
25302530
FunctionSize = 1

src/fsharp/PostInferenceChecks.fs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -511,10 +511,13 @@ let rec CheckExprNoByrefs (cenv:cenv) (env:env) expr =
511511
let tryExtractNameOf args =
512512
match args with
513513
| [Expr.App(Expr.Val(r,_,_),_,_,Expr.Const(constant,_,_)::_,_)] ->
514-
if r.CompiledName.StartsWith("get_") && constant = Const.Unit then // TODO: We need a better way to find static property getters
515-
Some(r.CompiledName.Substring(4))
516-
else
517-
None // the function was applied
514+
match constant with
515+
| Const.Unit ->
516+
if r.CompiledName.StartsWith("get_") then // TODO: We need a better way to find static property getters
517+
Some(r.CompiledName.Substring(4))
518+
else
519+
None // the function was applied
520+
| _ -> None
518521
| [Expr.App(Expr.Val(r,_,_),_,_,[],_)] -> Some(r.CompiledName)
519522
| [Expr.App(Expr.Val(r,_,_),_,_,_,_)] ->
520523
if r.CompiledName.StartsWith("get_") then // TODO: We need a better way to find member property getters

tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfAdditionExpr.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// #Regression #Conformance #DataExpressions
22
// Verify that nameof doesn't work on const string
3-
//<Expects id="FS3197" span="(5,9)" status="error">This expression does not have a name.</Expects>
3+
//<Expects id="FS3199" span="(5,9)" status="error">This expression does not have a name.</Expects>
44

55
let x = nameof(1+2)
66

tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfAppliedFunction.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// #Regression #Conformance #DataExpressions
22
// Verify that nameof doesn't work on applied functions
3-
//<Expects id="FS3197" span="(6,9)" status="error">This expression does not have a name.</Expects>
3+
//<Expects id="FS3199" span="(6,9)" status="error">This expression does not have a name.</Expects>
44

55
let f() = 1
66
let x = nameof(f())

tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfAsAFunction.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// #Regression #Conformance #DataExpressions
22
// Verify that nameof can't be used as a function.
3-
//<Expects id="FS3197" span="(5,9)" status="error">This expression does not have a name.</Expects>
3+
//<Expects id="FS3199" span="(5,9)" status="error">This expression does not have a name.</Expects>
44

55
let f = nameof
66

tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfDictLookup.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// #Regression #Conformance #DataExpressions
22
// Verify that nameof doesn't work on dictionary lookup
3-
//<Expects id="FS3197" span="(6,9)" status="error">This expression does not have a name.</Expects>
3+
//<Expects id="FS3199" span="(6,9)" status="error">This expression does not have a name.</Expects>
44

55
let dict = new System.Collections.Generic.Dictionary<int,string>()
66
let b = nameof(dict.[2])

tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfIntConst.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// #Regression #Conformance #DataExpressions
22
// Verify that nameof doesn't work on const int
3-
//<Expects id="FS3197" span="(5,9)" status="error">This expression does not have a name.</Expects>
3+
//<Expects id="FS3199" span="(5,9)" status="error">This expression does not have a name.</Expects>
44

55
let x = nameof 1
66

tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfIntegerAppliedFunction.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// #Regression #Conformance #DataExpressions
22
// Verify that nameof doesn't work on applied functions
3-
//<Expects id="FS3197" span="(6,9)" status="error">This expression does not have a name.</Expects>
3+
//<Expects id="FS3199" span="(6,9)" status="error">This expression does not have a name.</Expects>
44

55
let f x = 1 * x
66
let x = nameof(f 2)

tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfParameterAppliedFunction.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// #Regression #Conformance #DataExpressions
22
// Verify that nameof doesn't work on applied functions
3-
//<Expects id="FS3197" span="(7,9)" status="error">This expression does not have a name.</Expects>
3+
//<Expects id="FS3199" span="(7,9)" status="error">This expression does not have a name.</Expects>
44

55
let f x y = x y
66
let z x = 1 * x

tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfPartiallyAppliedFunction.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// #Regression #Conformance #DataExpressions
22
// Verify that nameof doesn't work on partially applied functions
3-
//<Expects id="FS3197" span="(6,9)" status="error">This expression does not have a name.</Expects>
3+
//<Expects id="FS3199" span="(6,9)" status="error">This expression does not have a name.</Expects>
44

55
let f x y = y * x
66
let x = nameof(f 2)

0 commit comments

Comments
 (0)