@Override
    public Type typeCheck(Scope<Type> scope) {
        Type type = context(String.format("while typechecking %s", this), this, () -> typeCheckLocal(scope));

        if (cachedType != null && !type.equals(cachedType)) {
            throw new RuntimeException(String.format("Checking type `%s` that doesn't match cached type `%s`",
                    type,
                    cachedType));
        }

        cachedType = type;
        return cachedType;
    }
Returns the type for this expression, throws a runtime exception if {@code typeCheck} has not been invoked.

@return the type.
smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/Expression.java