Skip to content

Commit 84a2dcb

Browse files
authored
IL test added (#16218)
1 parent f673b5a commit 84a2dcb

File tree

2 files changed

+102
-4
lines changed

2 files changed

+102
-4
lines changed

src/Compiler/AbstractIL/ilwrite.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ let canGenPropertyDef cenv (prop: ILPropertyDef) =
11891189
// If we have GetMethod or SetMethod set (i.e. not None), try and see if we have MethodDefs for them.
11901190
// NOTE: They can be not-None and missing MethodDefs if we skip generating them for reference assembly in the earlier pass.
11911191
// Only generate property if we have at least getter or setter, otherwise, we skip.
1192-
[| prop.GetMethod; prop.SetMethod |]
1192+
[| prop.GetMethod; prop.SetMethod |]
11931193
|> Array.choose id
11941194
|> Array.exists (MethodDefIdxExists cenv)
11951195

@@ -1300,14 +1300,14 @@ and GenTypeDefPass2 pidx enc cenv (tdef: ILTypeDef) =
13001300
// Now generate or assign index numbers for tables referenced by the maps.
13011301
// Don't yet generate contents of these tables - leave that to pass3, as
13021302
// code may need to embed these entries.
1303-
tdef.Implements |> List.iter (GenImplementsPass2 cenv env tidx)
1304-
events |> List.iter (GenEventDefPass2 cenv tidx)
1303+
tdef.Implements |> List.iter (GenImplementsPass2 cenv env tidx)
13051304
tdef.Fields.AsList() |> List.iter (GenFieldDefPass2 tdef cenv tidx)
13061305
tdef.Methods |> Seq.iter (GenMethodDefPass2 tdef cenv tidx)
1307-
// Generation of property definitions for **ref assemblies** is checking existence of generated method definitions.
1306+
// Generation of property & event definitions for **ref assemblies** is checking existence of generated method definitions.
13081307
// Therefore, due to mutable state within "cenv", order of operations matters.
13091308
// Who could have thought that using shared mutable state can bring unexpected bugs...?
13101309
props |> List.iter (GenPropertyDefPass2 cenv tidx)
1310+
events |> List.iter (GenEventDefPass2 cenv tidx)
13111311
tdef.NestedTypes.AsList() |> GenTypeDefsPass2 tidx (enc@[tdef.Name]) cenv
13121312
with exn ->
13131313
failwith ("Error in pass2 for type "+tdef.Name+", error: " + exn.Message)

tests/fsharp/Compiler/CodeGen/EmittedIL/ReferenceAssemblyTests.fs

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,104 @@ extends [runtime]System.Object
607607
608608
}"""]
609609

610+
[<Test>]
611+
let ``Cli events are emitted even for CliEvent members which are not last in a file`` () =
612+
FSharp """
613+
module LibraryWithTwoClassesAndTwoEvents
614+
open System
615+
616+
let event = new DelegateEvent<EventHandler<EventArgs>>()
617+
type MyClass() =
618+
[<CLIEvent>]
619+
member this.EventFromFirstType = event.Publish
620+
621+
let event2 = new DelegateEvent<EventHandler<EventArgs>>()
622+
type MyClass2() =
623+
[<CLIEvent>]
624+
member this.EventFromSecondType = event2.Publish
625+
"""
626+
|> withOptions ["--refonly"]
627+
|> compile
628+
|> shouldSucceed
629+
|> verifyIL [
630+
referenceAssemblyAttributeExpectedIL
631+
""".class auto ansi serializable nested public MyClass
632+
extends [runtime]System.Object
633+
{
634+
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 )
635+
.method public specialname rtspecialname
636+
instance void .ctor() cil managed
637+
{
638+
639+
.maxstack 8
640+
IL_0000: ldnull
641+
IL_0001: throw
642+
}
643+
644+
.method public hidebysig specialname
645+
instance void add_EventFromFirstType(class [runtime]System.EventHandler`1<class [runtime]System.EventArgs> 'handler') cil managed
646+
{
647+
648+
.maxstack 8
649+
IL_0000: ldnull
650+
IL_0001: throw
651+
}
652+
653+
.method public hidebysig specialname
654+
instance void remove_EventFromFirstType(class [runtime]System.EventHandler`1<class [runtime]System.EventArgs> 'handler') cil managed
655+
{
656+
657+
.maxstack 8
658+
IL_0000: ldnull
659+
IL_0001: throw
660+
}
661+
662+
.event class [runtime]System.EventHandler`1<class [runtime]System.EventArgs> EventFromFirstType
663+
{
664+
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.CLIEventAttribute::.ctor() = ( 01 00 00 00 )
665+
.addon instance void LibraryWithTwoClassesAndTwoEvents/MyClass::add_EventFromFirstType(class [runtime]System.EventHandler`1<class [runtime]System.EventArgs>)
666+
.removeon instance void LibraryWithTwoClassesAndTwoEvents/MyClass::remove_EventFromFirstType(class [runtime]System.EventHandler`1<class [runtime]System.EventArgs>)
667+
}
668+
}
669+
670+
.class auto ansi serializable nested public MyClass2
671+
extends [runtime]System.Object
672+
{
673+
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 )
674+
.method public specialname rtspecialname
675+
instance void .ctor() cil managed
676+
{
677+
678+
.maxstack 8
679+
IL_0000: ldnull
680+
IL_0001: throw
681+
}
682+
683+
.method public hidebysig specialname
684+
instance void add_EventFromSecondType(class [runtime]System.EventHandler`1<class [runtime]System.EventArgs> 'handler') cil managed
685+
{
686+
687+
.maxstack 8
688+
IL_0000: ldnull
689+
IL_0001: throw
690+
}
691+
692+
.method public hidebysig specialname
693+
instance void remove_EventFromSecondType(class [runtime]System.EventHandler`1<class [runtime]System.EventArgs> 'handler') cil managed
694+
{
695+
696+
.maxstack 8
697+
IL_0000: ldnull
698+
IL_0001: throw
699+
}
700+
701+
.event class [runtime]System.EventHandler`1<class [runtime]System.EventArgs> EventFromSecondType
702+
{
703+
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.CLIEventAttribute::.ctor() = ( 01 00 00 00 )
704+
.addon instance void LibraryWithTwoClassesAndTwoEvents/MyClass2::add_EventFromSecondType(class [runtime]System.EventHandler`1<class [runtime]System.EventArgs>)
705+
.removeon instance void LibraryWithTwoClassesAndTwoEvents/MyClass2::remove_EventFromSecondType(class [runtime]System.EventHandler`1<class [runtime]System.EventArgs>)
706+
""" ]
707+
610708
[<Test>]
611709
let ``Properties are emitted for CliMutable records`` () =
612710
FSharp """

0 commit comments

Comments
 (0)