Skip to content

Commit 76ea258

Browse files
committed
Take 2
1 parent 2639343 commit 76ea258

20 files changed

Lines changed: 219 additions & 22 deletions

src/Compiler/Checking/ConstraintSolver.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3688,7 +3688,7 @@ let CodegenWitnessArgForTraitConstraint tcVal g amap m traitInfo = trackErrors {
36883688
let ChooseTyparSolutionAndSolve css denv tp =
36893689
let g = css.g
36903690
let amap = css.amap
3691-
let max, m = ChooseTyparSolutionAndRange g amap tp
3691+
let max, m = ChooseTyparSolutionAndRange g amap tp
36923692
let csenv = MakeConstraintSolverEnv ContextInfo.NoContext css m denv
36933693
PostponeOnFailedMemberConstraintResolution csenv NoTrace
36943694
(fun csenv -> SolveTyparEqualsType csenv 0 m NoTrace (mkTyparTy tp) max)

src/Compiler/Checking/TypeRelations.fs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -134,50 +134,57 @@ let rec TypeFeasiblySubsumesType ndeep g amap m ty1 canCoerce ty2 =
134134
/// Here x gets a generalized type "list<'T>".
135135
let ChooseTyparSolutionAndRange (g: TcGlobals) amap (tp:Typar) =
136136
let m = tp.Range
137-
let maxTy, m =
137+
let (maxTy, isRefined), m =
138138
let initialTy =
139139
match tp.Kind with
140140
| TyparKind.Type -> g.obj_ty
141141
| TyparKind.Measure -> TType_measure Measure.One
142142
// Loop through the constraints computing the lub
143-
((initialTy, m), tp.Constraints) ||> List.fold (fun (maxTy, _) tpc ->
143+
(((initialTy, false), m), tp.Constraints) ||> List.fold (fun ((maxTy, isRefined), _) tpc ->
144144
let join m x =
145-
if TypeFeasiblySubsumesType 0 g amap m x CanCoerce maxTy then maxTy
146-
elif TypeFeasiblySubsumesType 0 g amap m maxTy CanCoerce x then x
147-
else errorR(Error(FSComp.SR.typrelCannotResolveImplicitGenericInstantiation((DebugPrint.showType x), (DebugPrint.showType maxTy)), m)); maxTy
145+
if TypeFeasiblySubsumesType 0 g amap m x CanCoerce maxTy then maxTy, isRefined
146+
elif TypeFeasiblySubsumesType 0 g amap m maxTy CanCoerce x then x, true
147+
else errorR(Error(FSComp.SR.typrelCannotResolveImplicitGenericInstantiation((DebugPrint.showType x), (DebugPrint.showType maxTy)), m)); maxTy, isRefined
148148
// Don't continue if an error occurred and we set the value eagerly
149-
if tp.IsSolved then maxTy, m else
149+
if tp.IsSolved then (maxTy, isRefined), m else
150150
match tpc with
151151
| TyparConstraint.CoercesTo(x, m) ->
152152
join m x, m
153153
| TyparConstraint.MayResolveMember(_traitInfo, m) ->
154-
maxTy, m
154+
(maxTy, isRefined), m
155155
| TyparConstraint.SimpleChoice(_, m) ->
156156
errorR(Error(FSComp.SR.typrelCannotResolveAmbiguityInPrintf(), m))
157-
maxTy, m
157+
(maxTy, isRefined), m
158158
| TyparConstraint.SupportsNull m ->
159-
maxTy, m
159+
(maxTy, isRefined), m
160160
| TyparConstraint.SupportsComparison m ->
161161
join m g.mk_IComparable_ty, m
162162
| TyparConstraint.SupportsEquality m ->
163-
maxTy, m
163+
(maxTy, isRefined), m
164164
| TyparConstraint.IsEnum(_, m) ->
165165
errorR(Error(FSComp.SR.typrelCannotResolveAmbiguityInEnum(), m))
166-
maxTy, m
166+
(maxTy, isRefined), m
167167
| TyparConstraint.IsDelegate(_, _, m) ->
168168
errorR(Error(FSComp.SR.typrelCannotResolveAmbiguityInDelegate(), m))
169-
maxTy, m
169+
(maxTy, isRefined), m
170170
| TyparConstraint.IsNonNullableStruct m ->
171171
join m g.int_ty, m
172172
| TyparConstraint.IsUnmanaged m ->
173173
errorR(Error(FSComp.SR.typrelCannotResolveAmbiguityInUnmanaged(), m))
174-
maxTy, m
174+
(maxTy, isRefined), m
175175
| TyparConstraint.RequiresDefaultConstructor m ->
176-
maxTy, m
176+
(maxTy, isRefined), m
177177
| TyparConstraint.IsReferenceType m ->
178-
maxTy, m
178+
(maxTy, isRefined), m
179179
| TyparConstraint.DefaultsTo(_priority, _ty, m) ->
180-
maxTy, m)
180+
(maxTy, isRefined), m)
181+
182+
match tp.Kind with
183+
| TyparKind.Type ->
184+
if not isRefined then
185+
warning(Error(FSComp.SR.typrelNeverRefinedAwayFromTop(), m))
186+
| TyparKind.Measure -> ()
187+
181188
maxTy, m
182189

183190
let ChooseTyparSolution g amap tp =

src/Compiler/Driver/CompilerDiagnostics.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ type PhasedDiagnostic with
380380
| 3389 -> false // tcBuiltInImplicitConversionUsed - off by default
381381
| 3390 -> false // xmlDocBadlyFormed - off by default
382382
| 3395 -> false // tcImplicitConversionUsedForMethodArg - off by default
383+
| 3559 -> false
383384
| _ ->
384385
(severity = FSharpDiagnosticSeverity.Info)
385386
|| (severity = FSharpDiagnosticSeverity.Warning && level >= x.WarningLevel)

src/Compiler/FSComp.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1672,4 +1672,5 @@ featureEscapeBracesInFormattableString,"Escapes curly braces before calling Form
16721672
3555,chkInstanceLetBindingOnStaticClasses,"If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Instance let bindings are not allowed."
16731673
3556,chkImplementingInterfacesOnStaticClasses,"If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Implementing interfaces is not allowed."
16741674
3557,chkAbstractMembersDeclarationsOnStaticClasses,"If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Abstract member declarations are not allowed."
1675-
3558,chkExplicitFieldsDeclarationsOnStaticClasses,"If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Explicit field declarations are not allowed."
1675+
3558,chkExplicitFieldsDeclarationsOnStaticClasses,"If a type uses both [<Sealed>] and [<AbstractClass>] attributes, it means it is static. Explicit field declarations are not allowed."
1676+
3559,typrelNeverRefinedAwayFromTop,"A type inference variable has been implicitly inferred to have type `obj`. Consider adding explicit type annotations. This warning is off by default and has been explicitly enabled for this project. You may suppress this warning by using #nowarn \"3525\"."

src/Compiler/xlf/FSComp.txt.cs.xlf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,11 @@
11371137
<target state="translated">Rozhraní {0} nemůžete implementovat se dvěma instancemi {1} a {2}, protože by se mohly sjednotit.</target>
11381138
<note />
11391139
</trans-unit>
1140+
<trans-unit id="typrelNeverRefinedAwayFromTop">
1141+
<source>A type inference variable has been implicitly inferred to have type `obj`. Consider adding explicit type annotations. This warning is off by default and has been explicitly enabled for this project. You may suppress this warning by using #nowarn \"3525\".</source>
1142+
<target state="new">A type inference variable has been implicitly inferred to have type `obj`. Consider adding explicit type annotations. This warning is off by default and has been explicitly enabled for this project. You may suppress this warning by using #nowarn \"3525\".</target>
1143+
<note />
1144+
</trans-unit>
11401145
<trans-unit id="undefinedNameFieldConstructorOrMemberWhenTypeIsKnown">
11411146
<source>The type '{0}' does not define the field, constructor or member '{1}'.</source>
11421147
<target state="translated">Typ {0} nedefinuje pole, konstruktor ani člen {1}.</target>
@@ -8284,4 +8289,4 @@
82848289
</trans-unit>
82858290
</body>
82868291
</file>
8287-
</xliff>
8292+
</xliff>

src/Compiler/xlf/FSComp.txt.de.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,11 @@
11371137
<target state="translated">Sie können die Schnittstelle "{0}" mit den beiden Instanziierungen "{1}" und "{2}" nicht implementieren, weil sie möglicherweise zusammengeführt werden.</target>
11381138
<note />
11391139
</trans-unit>
1140+
<trans-unit id="typrelNeverRefinedAwayFromTop">
1141+
<source>A type inference variable has been implicitly inferred to have type `obj`. Consider adding explicit type annotations. This warning is off by default and has been explicitly enabled for this project. You may suppress this warning by using #nowarn \"3525\".</source>
1142+
<target state="new">A type inference variable has been implicitly inferred to have type `obj`. Consider adding explicit type annotations. This warning is off by default and has been explicitly enabled for this project. You may suppress this warning by using #nowarn \"3525\".</target>
1143+
<note />
1144+
</trans-unit>
11401145
<trans-unit id="undefinedNameFieldConstructorOrMemberWhenTypeIsKnown">
11411146
<source>The type '{0}' does not define the field, constructor or member '{1}'.</source>
11421147
<target state="translated">Der Typ "{0}" definiert nicht das Feld, den Konstruktor oder den Member "{1}".</target>

src/Compiler/xlf/FSComp.txt.es.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,11 @@
11371137
<target state="translated">No se puede implementar la interfaz "{0}" con ambas creaciones de instancias, "{1}" y "{2}", porque pueden unificarse.</target>
11381138
<note />
11391139
</trans-unit>
1140+
<trans-unit id="typrelNeverRefinedAwayFromTop">
1141+
<source>A type inference variable has been implicitly inferred to have type `obj`. Consider adding explicit type annotations. This warning is off by default and has been explicitly enabled for this project. You may suppress this warning by using #nowarn \"3525\".</source>
1142+
<target state="new">A type inference variable has been implicitly inferred to have type `obj`. Consider adding explicit type annotations. This warning is off by default and has been explicitly enabled for this project. You may suppress this warning by using #nowarn \"3525\".</target>
1143+
<note />
1144+
</trans-unit>
11401145
<trans-unit id="undefinedNameFieldConstructorOrMemberWhenTypeIsKnown">
11411146
<source>The type '{0}' does not define the field, constructor or member '{1}'.</source>
11421147
<target state="translated">El tipo "{0}" no define el campo, constructor o miembro "{1}".</target>

src/Compiler/xlf/FSComp.txt.fr.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,11 @@
11371137
<target state="translated">Vous ne pouvez pas implémenter l'interface '{0}' avec les deux instanciations '{1}' et '{2}', car elles peuvent s'unifier.</target>
11381138
<note />
11391139
</trans-unit>
1140+
<trans-unit id="typrelNeverRefinedAwayFromTop">
1141+
<source>A type inference variable has been implicitly inferred to have type `obj`. Consider adding explicit type annotations. This warning is off by default and has been explicitly enabled for this project. You may suppress this warning by using #nowarn \"3525\".</source>
1142+
<target state="new">A type inference variable has been implicitly inferred to have type `obj`. Consider adding explicit type annotations. This warning is off by default and has been explicitly enabled for this project. You may suppress this warning by using #nowarn \"3525\".</target>
1143+
<note />
1144+
</trans-unit>
11401145
<trans-unit id="undefinedNameFieldConstructorOrMemberWhenTypeIsKnown">
11411146
<source>The type '{0}' does not define the field, constructor or member '{1}'.</source>
11421147
<target state="translated">Le type '{0}' ne définit pas le champ, le constructeur ou le membre '{1}'.</target>

src/Compiler/xlf/FSComp.txt.it.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,11 @@
11371137
<target state="translated">Non è possibile implementare l'interfaccia '{0}' con le due creazioni di istanze '{1}' e '{2}' perché possono essere unificate.</target>
11381138
<note />
11391139
</trans-unit>
1140+
<trans-unit id="typrelNeverRefinedAwayFromTop">
1141+
<source>A type inference variable has been implicitly inferred to have type `obj`. Consider adding explicit type annotations. This warning is off by default and has been explicitly enabled for this project. You may suppress this warning by using #nowarn \"3525\".</source>
1142+
<target state="new">A type inference variable has been implicitly inferred to have type `obj`. Consider adding explicit type annotations. This warning is off by default and has been explicitly enabled for this project. You may suppress this warning by using #nowarn \"3525\".</target>
1143+
<note />
1144+
</trans-unit>
11401145
<trans-unit id="undefinedNameFieldConstructorOrMemberWhenTypeIsKnown">
11411146
<source>The type '{0}' does not define the field, constructor or member '{1}'.</source>
11421147
<target state="translated">Il tipo '{0}' non definisce il campo, il costruttore o il membro '{1}'.</target>

src/Compiler/xlf/FSComp.txt.ja.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,11 @@
11371137
<target state="translated">統合している可能性があるため、'{1}' と '{2}' の 2 つのインスタンス化を含むインターフェイス '{0}' を実装することはできません。</target>
11381138
<note />
11391139
</trans-unit>
1140+
<trans-unit id="typrelNeverRefinedAwayFromTop">
1141+
<source>A type inference variable has been implicitly inferred to have type `obj`. Consider adding explicit type annotations. This warning is off by default and has been explicitly enabled for this project. You may suppress this warning by using #nowarn \"3525\".</source>
1142+
<target state="new">A type inference variable has been implicitly inferred to have type `obj`. Consider adding explicit type annotations. This warning is off by default and has been explicitly enabled for this project. You may suppress this warning by using #nowarn \"3525\".</target>
1143+
<note />
1144+
</trans-unit>
11401145
<trans-unit id="undefinedNameFieldConstructorOrMemberWhenTypeIsKnown">
11411146
<source>The type '{0}' does not define the field, constructor or member '{1}'.</source>
11421147
<target state="translated">型 '{0}' は、フィールド、コンストラクター、またはメンバー '{1}' を定義していません。</target>

0 commit comments

Comments
 (0)