Merge pull request #17596 from dotnet/merges/main-to-release/dev17.12

Merge main to release/dev17.12
This commit is contained in:
Kevin Ransom (msft) 2024-08-23 10:57:39 -07:00 коммит произвёл GitHub
Родитель c968e7a19a 12ee16f4fa
Коммит 14bc02fdcd
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
5 изменённых файлов: 111 добавлений и 10 удалений

Просмотреть файл

@ -2855,9 +2855,13 @@ module EstablishTypeDefinitionCores =
let hasMeasureAttr = HasFSharpAttribute g g.attrib_MeasureAttribute attrs
let hasStructAttr = HasFSharpAttribute g g.attrib_StructAttribute attrs
let hasCLIMutable = HasFSharpAttribute g g.attrib_CLIMutableAttribute attrs
// CLIMutableAttribute has a special treatment(specific error FS3132) in the case of records(Only record types may have this attribute.)
// So we want to keep these special treatment for records and avoid having two errors for the same attribute.
let reportAttributeTargetsErrors = g.langVersion.SupportsFeature(LanguageFeature.EnforceAttributeTargets) && not hasCLIMutable
let hasAllowNullLiteralAttr = HasFSharpAttribute g g.attrib_AllowNullLiteralAttribute attrs
// We want to keep these special attributes treatment and avoid having two errors for the same attribute.
let reportAttributeTargetsErrors =
g.langVersion.SupportsFeature(LanguageFeature.EnforceAttributeTargets)
&& not hasCLIMutable // CLIMutableAttribute has a special treatment(specific error FS3132)
&& not hasAllowNullLiteralAttr // AllowNullLiteralAttribute has a special treatment(specific errors FS0934, FS093)
let noCLIMutableAttributeCheck() =
if hasCLIMutable then errorR (Error(FSComp.SR.tcThisTypeMayNotHaveACLIMutableAttribute(), m))

Просмотреть файл

@ -0,0 +1,3 @@
[<AllowNullLiteral>]
type D() =
member x.P = 1

Просмотреть файл

@ -738,4 +738,56 @@ type InterruptibleLazy<'T> private (valueFactory: unit -> 'T) =
(Error 3132, Line 19, Col 8, Line 19, Col 19, "This type definition may not have the 'CLIMutable' attribute. Only record types may have this attribute.")
(Error 3132, Line 22, Col 8, Line 22, Col 17, "This type definition may not have the 'CLIMutable' attribute. Only record types may have this attribute.")
(Error 3132, Line 25, Col 8, Line 25, Col 18, "This type definition may not have the 'CLIMutable' attribute. Only record types may have this attribute.")
]
]
// SOURCE= E_AllowNullLiteral.fs # E_AllowNullLiteral.fs
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"E_AllowNullLiteral.fs"|])>]
let ``E_AllowNullLiteral 8.0`` compilation =
compilation
|> withLangVersion80
|> verifyCompile
|> shouldFail
|> withDiagnostics [
(Error 935, Line 15, Col 10, Line 15, Col 11, "Types with the 'AllowNullLiteral' attribute may only inherit from or implement types which also allow the use of the null literal")
(Error 934, Line 27, Col 10, Line 27, Col 11, "Records, union, abbreviations and struct types cannot have the 'AllowNullLiteral' attribute")
(Error 934, Line 30, Col 10, Line 30, Col 11, "Records, union, abbreviations and struct types cannot have the 'AllowNullLiteral' attribute")
(Error 934, Line 33, Col 10, Line 33, Col 11, "Records, union, abbreviations and struct types cannot have the 'AllowNullLiteral' attribute")
(Error 934, Line 36, Col 10, Line 36, Col 11, "Records, union, abbreviations and struct types cannot have the 'AllowNullLiteral' attribute")
(Error 934, Line 39, Col 10, Line 39, Col 13, "Records, union, abbreviations and struct types cannot have the 'AllowNullLiteral' attribute")
(Error 842, Line 41, Col 7, Line 41, Col 23, "This attribute is not valid for use on this language element")
(Error 842, Line 44, Col 7, Line 44, Col 23, "This attribute is not valid for use on this language element")
]
// SOURCE=E_AllowNullLiteral.fs # E_AllowNullLiteral.fs
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"E_AllowNullLiteral.fs"|])>]
let ``E_AllowNullLiteral preview`` compilation =
compilation
|> withLangVersionPreview
|> verifyCompile
|> shouldFail
|> withDiagnostics [
(Error 935, Line 15, Col 10, Line 15, Col 11, "Types with the 'AllowNullLiteral' attribute may only inherit from or implement types which also allow the use of the null literal")
(Error 934, Line 27, Col 10, Line 27, Col 11, "Records, union, abbreviations and struct types cannot have the 'AllowNullLiteral' attribute")
(Error 934, Line 30, Col 10, Line 30, Col 11, "Records, union, abbreviations and struct types cannot have the 'AllowNullLiteral' attribute")
(Error 934, Line 33, Col 10, Line 33, Col 11, "Records, union, abbreviations and struct types cannot have the 'AllowNullLiteral' attribute")
(Error 934, Line 36, Col 10, Line 36, Col 11, "Records, union, abbreviations and struct types cannot have the 'AllowNullLiteral' attribute")
(Error 934, Line 39, Col 10, Line 39, Col 13, "Records, union, abbreviations and struct types cannot have the 'AllowNullLiteral' attribute")
(Error 842, Line 41, Col 7, Line 41, Col 23, "This attribute is not valid for use on this language element");
(Error 842, Line 44, Col 7, Line 44, Col 23, "This attribute is not valid for use on this language element")
]
// SOURCE= AllowNullLiteral01.fs # AllowNullLiteral01.fs
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"AllowNullLiteral01.fs"|])>]
let ``AllowNullLiteral01 8.0`` compilation =
compilation
|> withLangVersion80
|> verifyCompile
|> shouldSucceed
// SOURCE=AllowNullLiteral01.fs # AllowNullLiteral01.fs
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"AllowNullLiteral01.fs"|])>]
let ``AllowNullLiteral01 preview`` compilation =
compilation
|> withLangVersionPreview
|> verifyCompile
|> shouldSucceed

Просмотреть файл

@ -0,0 +1,48 @@
module AllowNullLiteralTest = begin
//[<AllowNullLiteral>]
type I =
interface
abstract P : int
end
//[<AllowNullLiteral>]
type C() =
member x.P = 1
[<AllowNullLiteral>]
type D() =
inherit C()
interface I with
member x.P = 2
member x.P = 1
let d = (null : D)
let d2 = ((box null) :?> D)
[<AllowNullLiteral>] // expect an error here
type S(c:int) = struct end
[<AllowNullLiteral>] // expect an error here
type R = { r : int }
[<AllowNullLiteral>] // expect an error here
type U = A | B of int
[<AllowNullLiteral>] // expect an error here
type E = A = 1 | B = 2
[<AllowNullLiteral>] // expect an error here
type Del = delegate of int -> int
[<AllowNullLiteral>] // expect an error here
let x = 1
[<AllowNullLiteral>] // expect an error here
let f x = 1
end

6
tests/fsharp/typecheck/sigs/neg16.bsl поставляемый
Просмотреть файл

@ -3,20 +3,14 @@ neg16.fs(7,13,7,16): typecheck error FS0644: Namespaces cannot contain extension
neg16.fs(23,10,23,11): typecheck error FS0935: Types with the 'AllowNullLiteral' attribute may only inherit from or implement types which also allow the use of the null literal
neg16.fs(34,7,34,23): typecheck error FS0842: This attribute is not valid for use on this language element
neg16.fs(35,10,35,11): typecheck error FS0934: Records, union, abbreviations and struct types cannot have the 'AllowNullLiteral' attribute
neg16.fs(38,10,38,11): typecheck error FS0934: Records, union, abbreviations and struct types cannot have the 'AllowNullLiteral' attribute
neg16.fs(41,10,41,11): typecheck error FS0934: Records, union, abbreviations and struct types cannot have the 'AllowNullLiteral' attribute
neg16.fs(43,7,43,23): typecheck error FS0842: This attribute is not valid for use on this language element
neg16.fs(44,10,44,11): typecheck error FS0934: Records, union, abbreviations and struct types cannot have the 'AllowNullLiteral' attribute
neg16.fs(46,7,46,23): typecheck error FS0842: This attribute is not valid for use on this language element
neg16.fs(47,10,47,13): typecheck error FS0934: Records, union, abbreviations and struct types cannot have the 'AllowNullLiteral' attribute
neg16.fs(49,7,49,23): typecheck error FS0842: This attribute is not valid for use on this language element