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

Commitd1ba9ff

Browse files
thinkbeforecodingdsyme
authored andcommitted
Struct Records and Unions have ValueType super type (#3208)
* Struct Records and Unions have ValueType super type* Add qa tests for ValueType constraint on struct Records and Unions
1 parentf2d0be2 commitd1ba9ff

File tree

6 files changed

+28
-1
lines changed

6 files changed

+28
-1
lines changed

‎src/fsharp/TastOps.fs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,8 @@ let isUnionTy g ty = ty |> stripTyEqns g |> (function TType_app(tcr,_) -> t
717717
letisReprHiddenTy g ty= ty|> stripTyEqns g|>(function TType_app(tcr,_)-> tcr.IsHiddenReprTycon|_->false)
718718
letisFSharpObjModelTy g ty= ty|> stripTyEqns g|>(function TType_app(tcr,_)-> tcr.IsFSharpObjectModelTycon|_->false)
719719
letisRecdTy g ty= ty|> stripTyEqns g|>(function TType_app(tcr,_)-> tcr.IsRecordTycon|_->false)
720+
letisFSharpStructOrEnumTy g ty= ty|> stripTyEqns g|>(function TType_app(tcr,_)-> tcr.IsFSharpStructOrEnumTycon|_->false)
721+
letisFSharpEnumTy g ty= ty|> stripTyEqns g|>(function TType_app(tcr,_)-> tcr.IsFSharpEnumTycon|_->false)
720722
letisTyparTy g ty= ty|> stripTyEqns g|>(function TType_var_->true|_->false)
721723
letisAnyParTy g ty= ty|> stripTyEqns g|>(function TType_var_->true| TType_measure unt-> isUnitParMeasure g unt|_->false)
722724
letisMeasureTy g ty= ty|> stripTyEqns g|>(function TType_measure_->true|_->false)

‎src/fsharp/TastOps.fsi‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,8 @@ val isUnionTy : TcGlobals -> TType -> bool
414414
val isReprHiddenTy: TcGlobals-> TType-> bool
415415
val isFSharpObjModelTy: TcGlobals-> TType-> bool
416416
val isRecdTy: TcGlobals-> TType-> bool
417+
val isFSharpStructOrEnumTy: TcGlobals-> TType-> bool
418+
val isFSharpEnumTy: TcGlobals-> TType-> bool
417419
val isTyparTy: TcGlobals-> TType-> bool
418420
val isAnyParTy: TcGlobals-> TType-> bool
419421
val tryAnyParTy: TcGlobals-> TType-> Typar option

‎src/fsharp/infos.fs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ let GetSuperTypeOfType g amap m typ =
8787
Some g.obj_ty
8888
elif isStructTupleTy g typthen
8989
Some g.obj_ty
90+
elif isFSharpStructOrEnumTy g typthen
91+
if isFSharpEnumTy g typthen
92+
Some(g.system_Enum_typ)
93+
else
94+
Some(g.system_Value_typ)
9095
elif isRecdTy g typ|| isUnionTy g typthen
9196
Some g.obj_ty
9297
else
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// #Conformance #TypeConstraints
2+
// Struct Records should have the ValueType supertype constraint
3+
4+
[<Struct>]
5+
typeStructRec={
6+
Dummy:int
7+
}
8+
9+
letnullable= System.Nullable<StructRec>()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// #Conformance #TypeConstraints
2+
// Struct Unions should have the ValueType supertype constraint
3+
4+
[<Struct>]
5+
typeStructUnion= Caseofint
6+
7+
letnullable= System.Nullable<StructUnion>()

‎tests/fsharpqa/Source/Conformance/TypesAndTypeConstraints/CheckingSyntacticTypes/env.lst‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,6 @@ xSOURCE=NativePtrArrayElementUsage.fs SCFLAGS="--test:ErrorRanges" COMPILE_O
5151
SOURCE=E_ExplicitMemberConstraints1.fs# E_ExplicitMemberConstraints1.fs
5252
SOURCE=E_ExplicitMemberConstraints2.fs# E_ExplicitMemberConstraints2.fs
5353
SOURCE=E_ConstraintCall1.fs# E_ConstraintCall1.fs
54-
SOURCE=E_ConstraintCall2.fs# E_ConstraintCall2.fs
54+
SOURCE=E_ConstraintCall2.fs# E_ConstraintCall2.fs
55+
SOURCE=StructConstraint01.fs # StructConstraint01.fs
56+
SOURCE=StructConstraint02.fs # StructConstraint02.fs

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp