Skip to content

Instantly share code, notes, and snippets.

@agocke
Created July 6, 2022 23:34
Show Gist options
  • Save agocke/6556180733079acafa0f980b62b6eb94 to your computer and use it in GitHub Desktop.
Save agocke/6556180733079acafa0f980b62b6eb94 to your computer and use it in GitHub Desktop.
ref struct S<#a> {
public int Field;
public ref<#a> int RefField;
}
static int StaticField = 5;
public void M1() {
S s = default; // S<#global>
s = new S() { RefField = ref StaticField };
CC(ref s);
}
public void CC1<#a, #b>(ref<#a> S<#b> s) {
s = new S() {
RefField = ref s.Field // error, ref<#b> int <- ref<#a> int, #b and #a are unrelated
};
}
public void M2() {
S s = default; // S<#global>
s = new S() { RefField = ref StaticField };
CC(ref s); // error, invalid type parameters, ref s :: ref<#local> S<#global>
}
public void CC2<#a>(ref<#a> S<#a> s) {
s = new S() {
RefField = ref s.Field // OK
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment