From 4c9de67922b2381aed29c6dff2c892ff6467f114 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Tue, 19 Oct 2021 11:42:12 -0700 Subject: Nullable annotations part 4 (final) (#2300) * Nullable annotations part 4 (final) * PR feedback - Clean up extra variables introduced as nullable versions of existing variables. * Fix a few annotations - TryGetMethodStubValue may return null when true - GetReturnType and GetParameterType may return null in some cases * More annotations and PR feedback - Don't resolve a generic typeref that should already be a typedef - Remove some redundant null checks - Turn on nullable annotations for ref assembly - Remove #nullable disable section * Clean up GetInflatedDeclaringType - Remove null check - Replace TryResolve call with an assert - Add comment and asserts justifying null-forgiving operator * Replace exception with assert in accessors * PR feedback - Add parens to improve readability - Throw on diagnostic without message - Remove unnecessary string.empty * Undo DiagnosticString change - Some DiagnosticIds intentionally have no fixed format strings because we generate different strings in different circumstances. --- src/linker/Linker.Steps/BaseSubStep.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/linker/Linker.Steps/BaseSubStep.cs') diff --git a/src/linker/Linker.Steps/BaseSubStep.cs b/src/linker/Linker.Steps/BaseSubStep.cs index 9a3aa250a..4826c7014 100644 --- a/src/linker/Linker.Steps/BaseSubStep.cs +++ b/src/linker/Linker.Steps/BaseSubStep.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; +using System.Diagnostics; using Mono.Cecil; namespace Mono.Linker.Steps @@ -9,13 +11,19 @@ namespace Mono.Linker.Steps { protected AnnotationStore Annotations => Context.Annotations; - protected LinkContext Context { get; private set; } + LinkContext? _context { get; set; } + protected LinkContext Context { + get { + Debug.Assert (_context != null); + return _context; + } + } public abstract SubStepTargets Targets { get; } public virtual void Initialize (LinkContext context) { - Context = context; + _context = context; } public virtual bool IsActiveFor (AssemblyDefinition assembly) => true; -- cgit v1.2.3