Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit819e083

Browse files
Don't introduce another let to ref for base calls if ref is represented local var.
Fixesfsharp#669.
1 parent572ffe0 commit819e083

File tree

3 files changed

+72
-3
lines changed

3 files changed

+72
-3
lines changed

‎src/fsharp/TypeChecker.fs‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12306,6 +12306,11 @@ module IncrClassChecking =
1230612306
member localRep.IsValWithRepresentation (v:Val) =
1230712307
localRep.ValsWithRepresentation.Contains(v)
1230812308

12309+
member localRep.IsValRepresentedAsLocalVar (v:Val) =
12310+
match localRep.LookupRepr v with
12311+
| InVar false -> true
12312+
| _ -> false
12313+
1230912314
/// Make the elaborated expression that represents a use of a
1231012315
/// a "let v = ..." class binding
1231112316
member localRep.MakeValueLookup thisValOpt tinst safeStaticInitInfo v tyargs m =
@@ -12744,14 +12749,14 @@ module IncrClassChecking =
1274412749
// (c) rely on the fact that there are no 'let' bindings prior to the inherits expr.
1274512750
let inheritsExpr =
1274612751
match ctorInfo.InstanceCtorSafeThisValOpt with
12747-
| None ->
12748-
inheritsExpr
12749-
| Some v ->
12752+
| Some v when not (reps.IsValRepresentedAsLocalVar (v)) ->
1275012753
// Rewrite the expression to convert it to a load of a field if needed.
1275112754
// We are allowed to load fields from our own object even though we haven't called
1275212755
// the super class constructor yet.
1275312756
let ldexpr = reps.FixupIncrClassExprPhase2C (Some(thisVal)) safeStaticInitInfo thisTyInst (exprForVal m v)
1275412757
mkInvisibleLet m v ldexpr inheritsExpr
12758+
| _ ->
12759+
inheritsExpr
1275512760

1275612761
let spAtSuperInit = (if inheritsIsVisible then SequencePointsAtSeq else SuppressSequencePointOnExprOfSequential)
1275712762
mkSequential spAtSuperInit m inheritsExpr ctorBody
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// #Regression #Conformance #DeclarationElements #ObjectConstructors
2+
3+
// verify passing self to base class constructors works, see https://github.com/Microsoft/visualfsharp/issues/669
4+
5+
openSystem
6+
7+
typeParent(o:obj)=classend
8+
9+
typeParent<'t>(t:'t)=
10+
member valT= t
11+
12+
// this used to not work, causing NullReferenceException
13+
moduleImplicit=
14+
15+
// Instantiating this type should throw InvalidOperationException.
16+
typeBroken()as bself=
17+
inherit Parent(bself)
18+
19+
// this should work.
20+
typeOk()as self=
21+
inherit Parent<unit->Ok>(fun()-> self)
22+
23+
moduleExplicit=
24+
25+
// should throw InvalidOperationException.
26+
typeBroken=
27+
inherit Parent
28+
new()as gself={inherit Parent(gself)}
29+
30+
// this should work.
31+
typeOk=
32+
inherit Parent<unit->Ok>
33+
new()as self={inherit Parent<unit->Ok>(fun()-> self)}
34+
35+
36+
letcase1()=
37+
try
38+
letr= Implicit.Broken()
39+
false
40+
with
41+
|:? InvalidOperationException->true
42+
|_->false
43+
44+
letcase2()=
45+
try
46+
letr= Explicit.Broken()
47+
false
48+
with
49+
|:? InvalidOperationException->true
50+
|_->false
51+
52+
letcase3()=
53+
letr= Implicit.Ok().T()
54+
true
55+
56+
letcase4()=
57+
letr= Explicit.Ok().T()
58+
true
59+
60+
letresults=[ case1(); case2(); case3(); case4()]
61+
62+
doifnot(List.forall id results)then exit1else exit0

‎tests/fsharpqa/Source/Conformance/DeclarationElements/ObjectConstructors/env.lst‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
SOURCE=AlternateGenericTypeSyntax01.fs# AlternateGenericTypeSyntax01.fs
1515
SOURCE=MutuallyRecursive01.fs# MutuallyRecursive01.fs
16+
SOURCE=ImplicitCtorsCallingBaseclassPassingSelf.fs # ImplicitCtorsCallingBaseclassPassingSelf.fs
1617

1718
SOURCE=ExplicitCtors01.fs# ExplicitCtors01.fs
1819
SOURCE=WarningforLessGenericthanIndicated.fs# WarningforLessGenericthanIndicated.fs
1920
SOURCE=E_ExtraneousFields01.fs SCFLAGS="--test:ErrorRanges"# E_ExtraneousFields01.fs
21+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp