Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
87 lines (58 sloc) 2.82 KB

C# LDM Notes

Agenda

  1. Empty switch statement
  2. [DoesNotReturn] attribute
  3. Revisiting the param! null-checking feature

Discussion

Empty switch expression

Should the empty switch expression (expr switch { }) be an error?

Conclusion

We can't really find a reason to disallow this.

DoesNotReturn

The current design for the DoesNotReturnAttribute indicates that the method annotated with it is unreachable after a call to it for the purpose of flow analysis.

The questions are:

  1. Confirm that it only implies unreachability for nullability
  2. Confirm the name, which doesn't mention nullability

Conclusion

Yes to both questions. If we want to add general-case unreachability later we will do it through a different mechanism. That would require altered code generation (to ensure both verifiability and that the code after is truly unreachable) and is out of scope for the current feature set.

param!

We previously discussed the param! feature, which is meant to insert a throw if the parameter is null.

We'd like to confirm some of the details.

Illegal placement:

We think there should be diagnostics for the follow constructs:

  • Warning for default parameter value being null (e.g. void M(string p! = null))
  • Error on an out parameter
  • Error on methods without bodies
    • Including the declaration part of a partial
  • Warning if the type of the parameter is a nullable reference type or nullable value type
  • No place to put ! on the property setter

Semantics:

  • Should work with notnull constraint
  • Confirmed that the null checks should be the first possible code
    • Including before field initializers, iterator kick-off, constructor chaining
  • Do we want to use a well-known helper instead of throw?
    • CoreFX uses throw helpers, so it wouldn't be able to use the feature

Syntax:

It was previously mentioned that the syntax could be confusing because ! has different meanings in expressions or parameter names. Do we want to change the syntax?

Here are some syntax options we discussed:

  1. T p!
  2. T p!!
  3. T! p
  4. checked T p
  5. nonnull T p

We can't decide on a syntax right now. There are concerns that some of the proposed syntaxes are too verbose and remove the purpose of the feature. There's also a possible follow-on proposal: right now the ! syntax already has meaning in an expression context, but if we used a different syntax, like !!, we could also add a "null-checked expression" which does the same thing for expressions that it does for parameters. These ideas are interesting enough that we think we should hold the feature for the next C# version and discuss these possibilities more.

Conclusion

Some revisions to the feature and some open questions. We want the feature in some form and are committed to resolving these questions for the next release.

You can’t perform that action at this time.