← all packages

R6

no native code · R: 16 definitions, 11 typed strict, 13 gradual, prelude debt 3 · fuzzing: 9 definitions, 0 unsound, 5 accept calls outside their domain · tyr dc7f1a7 · Rsem 5c142d7 · NativeSem 770a1eb · rstt 2b2696f unpinned

R definitions

named top-level definitions
16 / 16 (100.0%)
not blocked by an unbound native symbol
16 / 16 (100.0%)
typed, gradual
13 / 16 (81.2%)
typed, strict
11 / 16 (68.8%)
3 of the strict failures are a name missing from the prelude.
mode
32 / 32

R definitions 32

R/R6-package.R

<statement> typed

timing: 0.002 s
source
"_PACKAGE"
R/R6-package.R:2

<statement> typed

timing: 0.000 s
source
NULL
R/R6-package.R:6
R/aaa.R

capsule typed

env
timing: 0.004 s
source
capsule <- new.env(hash = FALSE)
R/aaa.R:10

<statement> typed

timing: 0.001 s
source
attr(capsule, "name") <- "R6_capsule"
R/aaa.R:11

encapsulate untypeabletyped

unbound variable (line 15)
unbound: substitute — a name the prelude does not declare
error detail
name: substitute
gradual mode: typed
((expr: any) -> any)<>
timing: 0.002 s
source
encapsulate <- function(expr) {
  expr <- substitute(expr)
  eval(expr, capsule)
}
R/aaa.R:14

generator_funs typed

{ }<>
timing: 0.002 s
source
generator_funs <- list()
R/aaa.R:25
R/aslist.R

as.list.R6 untypeabletyped

unbound variable (line 11)
unbound: as.list.environment — a name the prelude does not declare
error detail
name: as.list.environment
gradual mode: typed
((x: any, ...: any) -> any)<>
timing: 0.003 s
source
as.list.R6 <- function(x, ...) {
  as.list.environment(x, all.names = TRUE)
}
R/aslist.R:10
R/clone.R

<statement> typed

timing: 7.46 s
source
generator_funs$clone_method <- function(deep = FALSE) {
  # Need to embed these utility functions inside this closure because the
  # environment of this function will change.

  # This takes a list of objects and a list of pairs of environments. For each
  # object, if it is a function, this checks if that function's environment is
  # the same as any of the `old` members of the pairs; if so, it will change
  # the function's environment to the matching `new` member. If the function's
  # environment is not found in the list, then it will not be touched.
  remap_func_envs <- function(objs, old_new_env_pairs) {
    lapply(objs, function(x) {
      if (is.function(x)) {
        func_env <- environment(x)

        for (i in seq_along(old_new_env_pairs)) {
          if (identical(func_env, old_new_env_pairs[[i]]$old)) {
            environment(x) <- old_new_env_pairs[[i]]$new
            break
          }
        }
      }

      x
    })
  }

  list2env2 <- function(x, envir = NULL, parent = emptyenv(),
                        hash = (length(x) >  100),
                        size = max(29L, length(x)),
                        empty_to_null = TRUE) {
    if (is.null(envir)) {
      envir <- new.env(hash = hash, parent = parent, size = size)
    }
    if (length(x) == 0) {
      if (empty_to_null)
        return(NULL)
      else
        return(envir)
    }
    list2env(x, envir)
  }

  # ---------------------------------------------------------------------------
  # Create representation of the old object
  # ---------------------------------------------------------------------------
  old <- list(
    list(
      enclosing = .subset2(self, ".__enclos_env__"),
      binding   = self,      # AKA the public binding environment
      private   = NULL
    )
  )

  if (!is.environment(old[[1]]$enclosing)) {
    stop("clone() must be called from an R6 object.")
  }

  old[[1]]$private <- old[[1]]$enclosing$private
  has_private <- !is.null(old[[1]]$private)

  # Figure out if we're in a portable class object
  portable <- !identical(old[[1]]$binding, old[[1]]$enclosing)

  # Traverse the super binding and enclosing environments, and add them to the
  # list.
  i <- 1
  while (TRUE) {
    if (is.null(old[[i]]$enclosing$super)) {
      break
    }

    old[[i+1]] <- list(
      binding   = old[[i]]$enclosing$super,
      enclosing = old[[i]]$enclosing$super$.__enclos_env__
    )

    i <- i + 1
  }

  # Set up stuff for deep clones
  if (deep) {
    if (has_private && is.function(old[[1]]$private$deep_clone)) {
      # Get private$deep_clone, if available.
      deep_clone <- old[[1]]$private$deep_clone
    } else {
      # If there's no private$deep_clone, then this default function will copy
      # fields that are R6 objects.
      deep_clone <- function(name, value) {
        # Check if it's an R6 object.
        is_r6_object <- is.environment(value) &&
          !is.null(get0(".__enclos_env__", value, inherits = FALSE))
        if (is_r6_object) {
          return(value$clone(deep = TRUE))
        }
        value
      }
    }
  }

  # We'll use these a lot later, and it's faster to refer to them directly.
  old_1_binding <- old[[1]]$binding
  old_1_private <- old[[1]]$private

  # ---------------------------------------------------------------------------
  # Create representation of the new object
  # ---------------------------------------------------------------------------

  # The object representation is made up of a list of "slices". Each slice
  # represents one level of inheritance. The first slice is somewhat different
  # from subsequent ones. The later ones are superclass slices. They do not
  # have a separate `private` environment.

  # Create the first slice. This one is different from the others.
  make_first_new_slice <- function(old_slice, portable) {
    new_slice <- list(
      enclosing = NULL,
      binding   = NULL
    )

    has_private <- !is.null(old_slice$private)

    if (portable) {
      enclosing_parent <- parent.env(old_slice$enclosing)
      binding_parent   <- emptyenv()

      if (has_private) {
        private_parent    <- emptyenv()
        new_slice$private <- new.env(private_parent, hash = FALSE)
      }
      new_slice$binding   <- new.env(binding_parent,   hash = FALSE)
      new_slice$enclosing <- new.env(enclosing_parent, hash = FALSE)

    } else {
      if (has_private) {
        private_parent    <- parent.env(old_slice$private)
        new_slice$private <- new.env(private_parent, hash = FALSE)

        binding_parent    <- new_slice$private
        new_slice$binding <- new.env(binding_parent, hash = FALSE)

      } else {
        binding_parent    <- parent.env(old_slice$binding)
        new_slice$binding <- new.env(binding_parent, hash = FALSE)
      }

      new_slice$enclosing <- new_slice$binding
    }

    # Set up self, private, and .__enclos_env__
    new_slice$enclosing$self <- new_slice$binding
    if (has_private) {
      new_slice$enclosing$private <- new_slice$private
    }
    new_slice$binding$.__enclos_env__ <- new_slice$enclosing

    new_slice
  }


  # This creates a slice other than the first one.
  make_new_slice <- function(old_slice, self, private, enclosing_parent) {
    enclosing <- new.env(enclosing_parent, hash = FALSE)
    binding   <- new.env(emptyenv(), hash = FALSE)

    enclosing$self <- self
    if (!is.null(private)) {
      enclosing$private <- private
    }

    binding$.__enclos_env__ <- enclosing

    list(
      enclosing = enclosing,
      binding = binding
    )
  }

  new <- list(
    make_first_new_slice(old[[1]], portable)
  )

  # We'll use these a lot, and it's faster to refer to them directly.
  new_1_binding   <- new[[1]]$binding
  new_1_private   <- new[[1]]$private
  new_1_enclosing <- new[[1]]$enclosing

  # Mirror the super environments from the old object
  if (length(old) > 1) {
    for (i in seq.int(2, length(old))) {
      if (portable) {
        enclosing_parent <- parent.env(old[[i]]$enclosing)
      } else {
        enclosing_parent <- new_1_enclosing
      }

      new[[i]] <- make_new_slice(
        old[[i]],
        new_1_binding,
        new_1_private,
        enclosing_parent
      )
R/clone.R:3
R/env_utils.R

<statement> timeout

timing: 20.00 s
source
encapsulate({
  # Search a list for all function objects, change the environment for those
  # functions to a target environment, and return the modified list.
  assign_func_envs <- function(objs, target_env) {
    if (is.null(target_env)) return(objs)

    lapply(objs, function(x) {
      if (is.function(x)) environment(x) <- target_env
      x
    })
  }

  # Get names of all superclasses
  get_superclassnames <- function(inherit) {
    if (is.null(inherit)) return(NULL)
    c(inherit$classname, get_superclassnames(inherit$get_inherit()))
  }

  # Wrapper around list2env with a NULL check. In R <3.2.0, if an empty unnamed
  # list is passed to list2env(), it errors. But an empty named list is OK. For
  # R >=3.2.0, this wrapper is not necessary.
  # @param empty_to_null Controls what to do when x is NULL or empty list.
  #   If TRUE, return NULL. If FALSE, return an empty list.
  list2env2 <- function(x, envir = NULL, parent = emptyenv(),
                        hash = (length(x) >  100),
                        size = max(29L, length(x)),
                        empty_to_null = TRUE) {
    if (is.null(envir)) {
      envir <- new.env(hash = hash, parent = parent, size = size)
    }
    if (length(x) == 0) {
      if (empty_to_null)
        return(NULL)
      else
        return(envir)
    }
    list2env(x, envir)
  }
})
R/env_utils.R:1
R/generator_funs.R

<statement> typed

timing: 0.001 s
source
generator_funs$get_inherit <- function() {
  # The NULL arg speeds up eval a tiny bit
  eval(inherit, parent_env, NULL)
}
R/generator_funs.R:2

<statement> typed

timing: 0.056 s
source
generator_funs$has_private <- function() {
  inherit <- get_inherit()
  if (!is.null(private_fields) || !is.null(private_methods))
    TRUE
  else if (is.null(inherit))
    FALSE
  else
    inherit$has_private()
}
R/generator_funs.R:12

<statement> skipped

error detail
Invalid_argument("Cannot assign to an immutable variable.")
timing: 0.025 s
source
generator_funs$set <- function(which = NULL, name = NULL, value, overwrite = FALSE) {
  if (lock_class)
    stop("Can't modify a locked R6 class.")

  if (is.null(which) || !(which %in% c("public", "private", "active")))
    stop("`which` must be 'public', 'private', or 'active'.")

  if (is.null(name) || !is.character(name))
    stop("`name` must be a string.")

  if (missing(value))
    stop("`value` must be provided.")

  # Find which group this object should go in.
  if (which == "public") {
    group <- if (is.function(value)) "public_methods" else "public_fields"
  } else if (which == "private") {
    group <- if (is.function(value)) "private_methods" else "private_fields"
  } else if (which == "active") {
    if (is.function(value))
      group <- "active"
    else
      stop("Can't add non-function to active")
  }

  # Check that it's not already present
  all_groups <- c("public_methods", "public_fields", "private_methods",
                  "private_fields", "active")

  # If we're allowed to overwrite, don't check the group that this object
  # would go in.
  if (overwrite)
    all_groups <- setdiff(all_groups, group)

  all_names <- unlist(lapply(all_groups, function(g) names(get(g))))

  if (name %in% all_names) {
    stop("Can't add ", name, " because it already present in ", classname,
         " generator.")
  }

  # Assign in correct group. Create group if it doesn't exist.
  if (is.null(self[[group]]))
    self[[group]] <- list()

  if (is.null(value)) {
    # If it's NULL, the item should get a NULL value. The `[[<-` assignment
    # would instead delete the item; this method gives it a NULL value.
    self[[group]][name] <- list(NULL)
  } else {
    self[[group]][[name]] <- value
  }

  invisible()
}
R/generator_funs.R:25

<statement> skipped

error detail
Invalid_argument("Cannot assign to an immutable variable.")
timing: 0.003 s
source
generator_funs$debug <- function(name) {
  debug_names <<- union(debug_names, name)
}
R/generator_funs.R:84

<statement> skipped

error detail
Invalid_argument("Cannot assign to an immutable variable.")
timing: 0.001 s
source
generator_funs$undebug <- function(name) {
  debug_names <<- setdiff(debug_names, name)
}
R/generator_funs.R:89

<statement> skipped

error detail
Invalid_argument("Cannot assign to an immutable variable.")
timing: 0.000 s
source
generator_funs$lock <- function() {
  lock_class <<- TRUE
}
R/generator_funs.R:93

<statement> skipped

error detail
Invalid_argument("Cannot assign to an immutable variable.")
timing: 0.000 s
source
generator_funs$unlock <- function() {
  lock_class <<- FALSE
}
R/generator_funs.R:97

<statement> typed

timing: 0.000 s
source
generator_funs$is_locked <- function() {
  lock_class
}
R/generator_funs.R:101
R/is.R

is.R6 typed any: x fuzz ok

((x: any) -> LGL1<>)<>
timing: 0.014 s
fuzzing: 8 inside (8 ok) · 3 outside (3 rejected)
source
is.R6 <- function(x) {
  inherits(x, "R6")
}
R/is.R:22

is.R6Class typed any: x fuzz ok

((x: any) -> LGL1<>)<>
timing: 0.012 s
fuzzing: 6 inside (6 ok) · 7 outside (7 rejected)
source
is.R6Class <- function(x) {
  inherits(x, "R6ClassGenerator")
}
R/is.R:28
R/new.R

<statement> typed

timing: 0.332 s
source
generator_funs$new <- function(...) {
  # Get superclass object -------------------------------------------
  inherit <- get_inherit()

  # Some checks on superclass ---------------------------------------
  if (!is.null(inherit)) {
    if (!inherits(inherit, "R6ClassGenerator"))
      stop("`inherit` must be a R6ClassGenerator.")

    if (!identical(portable, inherit$portable))
      stop("Sub and superclass must both be portable or non-portable.")

    # Merge fields over superclass fields, recursively --------------
    recursive_merge <- function(obj, which) {
      if (is.null(obj)) return(NULL)
      merge_vectors(recursive_merge(obj$get_inherit(), which), obj[[which]])
    }
    public_fields  <- merge_vectors(recursive_merge(inherit, "public_fields"),
                                    public_fields)
    private_fields <- merge_vectors(recursive_merge(inherit, "private_fields"),
                                    private_fields)
  }

  if (class) {
    classes <- c(classname, get_superclassnames(inherit), "R6")
  } else {
    classes <- NULL
  }

  # Precompute some things ------------------------------------------
  has_priv <- has_private()


  # Create binding and enclosing environments -----------------------
  if (portable) {
    # When portable==TRUE, the public binding environment is separate from the
    # enclosing environment.

    # Binding environment for private objects (where private objects are found)
    if (has_priv)
      private_bind_env <- new.env(parent = emptyenv(), hash = FALSE)
    else
      private_bind_env <- NULL

    # Binding environment for public objects (where public objects are found)
    public_bind_env <- new.env(parent = emptyenv(), hash = FALSE)

    # The enclosing environment for methods
    enclos_env <- new.env(parent = parent_env, hash = FALSE)

  } else {
    # When portable==FALSE, the public binding environment is the same as the
    # enclosing environment.
    # If present, the private binding env is the parent of the public binding
    # env.
    if (has_priv) {
      private_bind_env <- new.env(parent = parent_env, hash = FALSE)
      public_bind_env <- new.env(parent = private_bind_env, hash = FALSE)
    } else {
      private_bind_env <- NULL
      public_bind_env <- new.env(parent = parent_env, hash = FALSE)
    }

    enclos_env <- public_bind_env
  }

  # Add self and private pointer ------------------------------------
  enclos_env$self <- public_bind_env
  if (has_priv)
    enclos_env$private <- private_bind_env

  # Fix environment for methods -------------------------------------
  public_methods <- assign_func_envs(public_methods, enclos_env)
  if (has_priv)
    private_methods <- assign_func_envs(private_methods, enclos_env)
  if (!is.null(active))
    active <- assign_func_envs(active, enclos_env)

  # Enable debugging ------------------------------------------------
  if (length(debug_names) > 0) {
    lapply(public_methods[names(public_methods) %in% debug_names], base::debug)
    lapply(private_methods[names(private_methods) %in% debug_names], base::debug)
    lapply(active[names(active) %in% debug_names], base::debug)
  }

  # Set up superclass objects ---------------------------------------
  if (!is.null(inherit)) {
    if (portable) {
      # Set up the superclass objects
      super_struct <- create_super_env(inherit, public_bind_env,
                                       private_bind_env, portable = TRUE)
    } else {
      # Set up the superclass objects
      super_struct <- create_super_env(inherit, public_bind_env, portable = FALSE)
    }

    enclos_env$super <- super_struct$bind_env

    # Merge this level's methods over the superclass methods
    public_methods  <- merge_vectors(super_struct$public_methods, public_methods)
    private_methods <- merge_vectors(super_struct$private_methods, private_methods)
    active          <- merge_vectors(super_struct$active, active)

    # If `cloneable` property differs between sub and superclass
    # - super will override sub if super doesn't allow cloning
    # - sub will override super if super allows cloning
    if (!identical(cloneable, inherit$cloneable)) {
      public_methods[["clone"]] <- NULL

      if (!inherit$cloneable) {
        message(
          "Superclass ", inherit$classname, " has cloneable=FALSE, but subclass ", classname, " has cloneable=TRUE. ",
          "A subclass cannot be cloneable when its superclass is not cloneable, so cloning will be disabled for ", classname, "."
        )
      }
    }
  }

  # Copy objects to public bind environment -------------------------
  list2env2(public_methods, envir = public_bind_env)
  list2env2(public_fields, envir = public_bind_env)

  # Copy objects to private bind environment ------------------------
  if (has_priv) {
    list2env2(private_methods, envir = private_bind_env)
    list2env2(private_fields, envir = private_bind_env)
  }

  # Set up active bindings ------------------------------------------
  if (!is.null(active)) {
    for (name in names(active)) {
      makeActiveBinding(name, active[[name]], public_bind_env)
    }

    # If there are active bindings, then we need to store a copy of the active
    # bindings in case the object is cloned. This is because as of R 4.0,
    # there's no way to get the function associated with an active binding;
    # you can only get the return value.
    enclos_env$`.__active__` <- active
  }


  # Add refs to other environments in the object --------------------
  public_bind_env$`.__enclos_env__` <- enclos_env

  # Lock ------------------------------------------------------------
  if (lock_objects) {
    if (has_priv) lockEnvironment(private_bind_env)
    lockEnvironment(public_bind_env)
  }

  # Always lock methods
  if (has_priv) {
    for (name in names(private_methods))
      lockBinding(name, private_bind_env)
  }
  for (name in names(public_methods))
    lockBinding(name, public_bind_env)

  class(public_bind_env) <- classes

  # Initialize ------------------------------------------------------
  initialize <- .subset2(public_bind_env, "initialize")
  if (is.function(initialize)) {
    initialize(...)
  } else if (length(list(...)) != 0 ) {
    stop("Called new() with arguments, but there is no initialize method.")
  }

  # Finalizer -------------------------------------------------------
  if (is.function(.subset2(public_bind_env, "finalize"))) {
    # This wraps the user's `finalize` method. The user's finalize method
    # typically does not have an `e` argument, so the wrapper needs to consume
    # the `e` argument.
    finalizer_wrapper <- function(e) {
      .subset2(e, "finalize")()
    }
    # Reassign the wrapper's environment so that it does not capture the current
    # environment and prevent objects from getting GC'd.
    environment(finalizer_wrapper) <- baseenv()

    reg.finalizer(
      public_bind_env,
      finalizer_wrapper,
      onexit = TRUE
    )
  }

  if (has_priv) {
    if (is.function(.subset2(private_bind_env, "finalize"))) {
      finalizer_wrapper <- function(e) {
        .subset2(e, ".__enclos_env__")$private$finalize()
      }
      environment(finalizer_wrapper) <- baseenv()
      reg.finalizer(
        public_bind_env,
        finalizer_wrapper,
        onexit = TRUE
      )
    }
  }
R/new.R:4

<statement> untypeable

untypeable application of base::$<- (line 242)
error detail
argument: @(env, ".__enclos_env__"<>, v: env)
failing call: base::$<-(new.env(), ".__enclos_env__", v = new.env())
timing: 1.85 s
source
encapsulate({
  # Create and populate the self$super environment, for non-portable case.
  # In this function, we "climb to the top" of the superclass hierarchy by
  # recursing early on in the function, and then fill the methods downward by
  # doing the work for each level and passing the needed information down.
  create_super_env <- function(inherit, public_bind_env, private_bind_env = NULL,
                               portable = TRUE) {
    public_methods  <- inherit$public_methods
    private_methods <- inherit$private_methods
    active          <- inherit$active

    # Set up super enclosing and binding environments -------------------

    # The environment in which functions run is a child of the public bind env
    # (AKA self).
    # For portable classes, this is a child of the superclass's parent env.
    # For non-portable classes, this is a child of self; however, self has no
    # bindings that point to it. The only reason this environment is needed is so
    # that if a function super$foo in turn calls super$bar, it will be able to
    # find bar from the next superclass up.
    if (portable)
      enclos_parent <- inherit$parent_env
    else
      enclos_parent <- public_bind_env

    super_enclos_env <- new.env(parent = enclos_parent, hash = FALSE)

    # The binding environment is a new environment. Its parent doesn't matter
    # because it's not the enclosing environment for any functions.
    super_bind_env <- new.env(parent = emptyenv(), hash = FALSE)

    # Need to store the enclosing environment for cloning.
    super_bind_env$.__enclos_env__ <- super_enclos_env

    # Add self/private pointers -----------------------------------------
    if (portable) {
      super_enclos_env$self <- public_bind_env
      if (!is.null(private_bind_env))
        super_enclos_env$private <- private_bind_env
    }

    # Set up method environments ----------------------------------------
    # All the methods can be found in self$super (the binding env).
    # Their enclosing env is a different environment.
    public_methods  <- assign_func_envs(public_methods, super_enclos_env)
    private_methods <- assign_func_envs(private_methods, super_enclos_env)
    active          <- assign_func_envs(active, super_enclos_env)

    # Recurse if there are more superclasses ----------------------------
    inherit_inherit <- inherit$get_inherit()
    if (!is.null(inherit_inherit)) {
      super_struct <- create_super_env(inherit_inherit, public_bind_env,
                                       private_bind_env, portable)
      super_enclos_env$super <- super_struct$bind_env

      # Merge this level's methods over the superclass methods
      public_methods  <- merge_vectors(super_struct$public_methods, public_methods)
      private_methods <- merge_vectors(super_struct$private_methods, private_methods)
      active          <- merge_vectors(super_struct$active, active)
    }

    # Copy the methods into the binding environment ---------------------
    list2env2(public_methods, envir = super_bind_env)
    list2env2(private_methods, envir = super_bind_env)
    if (!is.null(active)) {
      for (name in names(active)) {
        makeActiveBinding(name, active[[name]], super_bind_env)
      }
      # If there are active bindings, then we need to store a copy of the
      # active bindings in case the object is cloned.
      super_enclos_env$`.__active__` <- active
    }

    # Return an object with all the information needed to merge down
    list(
      bind_env = super_bind_env,
      public_methods = public_methods,
      private_methods = private_methods,
      active = active
    )
  }
})
R/new.R:210
R/print.R

indent typed any: indent accepts outside

(((str: vec, indent: any?) -> CHR<>)&((str: vec1, indent: any?) -> CHR1<>))<>
timing: 0.095 s
fuzzing: 8 inside (5 ok, 3 error type) · 8 outside (6 rejected, 2 accepted)

Accepted outside the domain str: 2

parameterchangecallreturned
strkind:listindent(list())(CHR & ~vec1)<> with { }
strkind:symindent("str" = as.name("x"))"x"<> with { }

Other calls inside the domain

callverdicterror
indent(NA_integer_, new.env())error_typebase::paste: environments cannot be coerced to other types
indent(NA, "indent" = as.name("x"))error_typebase::paste: 'symbol' object cannot be coerced to type 'double'
indent(2L, function(...) NULL)error_typebase::paste: cannot coerce type 'closure' to vector of type 'double'
source
indent <- function(str, indent = 0) {
  gsub("(^|\\n)(?!$)",
    paste0("\\1", paste(rep(" ", indent), collapse = "")),
    str,
    perl = TRUE
  )
}
R/print.R:130

trim typed accepts outside

∀'a. (((str: 'a & vec, n: dbl<~@"-", ...>?) -> CHR<> | vec & 'a)&((str: 'a & vec1, n: dbl1<~@"-", ...>?) -> CHR1<> | vec1 & 'a)&((str: 'a & vec1, n: dbl<~@"-", ...>?) -> CHR<> | (CHR<> | vec1) & 'a))<>
timing: 0.755 s
fuzzing: 19 inside (9 ok, 10 error type) · 8 outside (6 rejected, 2 accepted)
type drawn from: (((str: 'str & vec, n: dbl<~@"-", ...>?) -> CHR<> | vec & 'str) & ((str: 'str & vec1, n: dbl1<~@"-", ...>?) -> CHR1<> | vec1 & 'str) & ((str: 'str & vec1, n: dbl<~@"-", ...>?) -> CHR<> | (CHR<> | vec1) & 'str))<>

Accepted outside the domain str: 2

parameterchangecallreturned
strwraptrim(list(integer(0))){ (INT & ~vec1)<> with { } }<> with { }
strwraptrim(list(2147483647), 2L)" ..."<> with { }

Other calls inside the domain

callverdicterror
trim("str" = NA)error_typebase::if: missing value where TRUE/FALSE needed
trim(NA)error_typebase::if: missing value where TRUE/FALSE needed
trim(integer(0))error_typebase::if: argument is of length zero
trim("str" = c(2, Inf, 2147483647, 2147483647, -1), "n" = c(1L, 2L, 0L, 2147483647L, 2L))error_typebase::if: the condition has length > 1
trim(0, as.raw(c(0)))error_typebase::-: non-numeric argument to binary operator
trim(NA_complex_)error_typebase::if: missing value where TRUE/FALSE needed
and 4 more
source
trim <- function(str, n = 60) {
  if (nchar(str) > n) paste(substr(str, 1, n-4), "...")
  else str
}
R/print.R:139

object_summaries timeout untypeable → timeout

timing: 20.00 s
source
object_summaries <- function(x, exclude = NULL) {
  if (length(x) == 0)
    return(NULL)

  if (is.list(x))
    obj_names <- names(x)
  else if (is.environment(x))
    obj_names <- ls(x, all.names = TRUE)

  obj_names <- setdiff(obj_names, exclude)

  values <- vapply(obj_names, function(name) {
    if (is.environment(x) && bindingIsActive(name, x)) {
      "active binding"
    } else {
      obj <- .subset2(x, name)
      if (is.function(obj)) deparse(args(obj))[[1L]]
      # Plain environments (not envs with classes, like R6 or RefClass objects)
      else if (is.environment(obj) && identical(class(obj), "environment")) "environment"
      else if (is.null(obj)) "NULL"
      else if (is.atomic(obj)) {
        # If obj has many elements, paste() can be very slow, so we'll just
        # use just a subset of it. https://github.com/r-lib/R6/issues/159
        txt <- as.character(utils::head(obj, 60))
        txt <- paste(txt, collapse = " ")
        trim(txt)
      }
      else paste(class(obj), collapse = ", ")
    }
  }, FUN.VALUE = character(1))

  paste0(obj_names, ": ", values, sep = "")
}
R/print.R:94

format.R6 typed accepts outside

∀'a,'b,`a. ((x: { format: @(...: ('a, empty? | `a)) -> 'b, any }, ...: ('a, `a)) -> 'b)<>
gradual mode: typed
∀'a,'b,`a. (((x: vec, ...: ('a, `a)) | (x: { .__enclos_env__: vec, ~arrow }, ...: ('a, `a)) | (x: { .__enclos_env__: { null }, ~arrow }, ...: ('a, `a)) | (x: { .__enclos_env__: { private: null, any }, ~arrow }, ...: ('a, `a)) | (x: { .__enclos_env__: { private: ~null, any }, ~arrow }, ...: ('a, `a)) | (x: { format: ~arrow, .__enclos_env__: vec, any }, ...: ('a, `a)) | (x: { format: ~arrow, .__enclos_env__: { null }, any }, ...: ('a, `a)) | (x: { format: ~arrow, .__enclos_env__: { private: null, any }, any }, ...: ('a, `a)) | (x: { format: ~arrow, .__enclos_env__: { private: ~null, any }, any }, ...: ('a, `a)) -> CHR1<>)&((x: { format: @(...: ('a, empty? | `a)) -> 'b, any }, ...: ('a, `a)) -> 'b))<>
timing: 1.27 s
fuzzing: 24 inside (24 ok) · 8 outside (6 rejected, 2 accepted)
type drawn from: ((x: { format: @(...: ('_ell, empty? | `_ell)) -> 'I1784, any }, ...: ('_ell, `_ell)) -> 'I1784)<>

Accepted outside the domain x: 2

parameterchangecallreturned
xwrapformat.R6("x" = list(list("format" = function(...) 2)))"<list>\n Public:\n : "<> with { }
xwrapformat.R6(list(list("format" = function(...) c(complex(real = 0, imaginary = 0), complex(real = 0, imaginary = 0)), function(...) NULL)), 0.5, 0, "fuzz_dot1" = list(NULL, NULL), "fuzz_dot2" = as.raw(c(255, 0, 0, 255, 255)))"<list>\n Public:\n : "<> with { }
source
format.R6 <- function(x, ...) {
  if (is.function(.subset2(x, "format"))) {
    .subset2(x, "format")(...)
  } else {
    ret <- paste0("<", class(x)[1], ">")

    # If there's another class besides first class and R6
    classes <- setdiff(class(x), "R6")
    if (length(classes) >= 2) {
      ret <- c(ret, paste0("  Inherits from: <", classes[2], ">"))
    }

    ret <- c(ret,
      "  Public:",
      indent(object_summaries(x, exclude = c(".__active__", ".__enclos_env__")), 4)
    )

    private <- .subset2(.subset2(x, ".__enclos_env__"), "private")
    if (!is.null(private)) {
      ret <- c(ret,
        "  Private:",
        indent(object_summaries(private), 4)
      )
    }
    paste(ret, collapse = "\n")
  }
}
R/print.R:2

print.R6 typed accepts outside

∀'a,'b,`a. ((x: 'a & vec, ...: ('b, `a)) | (x: 'a & { print: @(...: ('b, empty? | `a)) -> any, any }, ...: ('b, `a)) | (x: 'a & { print: ~arrow, any }, ...: ('b, `a)) | (x: 'a & { ~arrow }, ...: ('b, `a)) -> 'a)<>
timing: 1.59 s
fuzzing: 24 inside (1 ok, 23 error type) · 8 outside (2 rejected, 6 accepted)
type drawn from: ((x: 'x & vec, ...: ('_ell, `_ell)) | (x: 'x & { print: @(...: ('_ell, empty? | `_ell)) -> any, any }, ...: ('_ell, `_ell)) | (x: 'x & { print: ~arrow, any }, ...: ('_ell, `_ell)) | (x: 'x & { ~arrow }, ...: ('_ell, `_ell)) -> 'x)<>

Accepted outside the domain x: 6

parameterchangecallreturned
xkind:langprint.R6(quote(f(x)), character(0))lang<> with { }
xkind:langprint.R6("x" = quote(f(x)))lang<> with { }
xkind:nullprint.R6(NULL)null
xkind:nullprint.R6(NULL, -Inf)null
xkind:nullprint.R6(NULL, as.raw(c(0, 0, 0, 255, 0)), as.raw(c(255)), "fuzz_dot1" = function(...) as.name("x"), "fuzz_dot2" = quote(f(x)))null
xunwrapprint.R6(new.env(), "", "", "fuzz_dot1" = NULL)env<> with { }

Other calls inside the domain

callverdicterror
print.R6(complex(real = 0, imaginary = 0))error_typebase::.subset2: subscript out of bounds
print.R6(c("", "x y", "a", "a", "é"), 1L, "fuzz_dot1" = local({ p <- unserialize(serialize(new("externalptr"), NULL)); attributes(p) <- NULL; p }), "fuzz_dot2" = new.env())error_typebase::.subset2: subscript out of bounds
print.R6(as.raw(c(255, 255)), -Inf)error_typebase::.subset2: subscript out of bounds
print.R6(42, complex(0))error_typebase::.subset2: subscript out of bounds
print.R6("a", character(0))error_typebase::.subset2: subscript out of bounds
print.R6(structure(42L, "levels" = character(0), class = "factor"), as.raw(c(0, 0, 0, 255, 0)), as.raw(c(255)), "fuzz_dot1" = function(...) as.name("x"), "fuzz_dot2" = quote(f(x)))error_typebase::.subset2: subscript out of bounds
and 17 more
source
print.R6 <- function(x, ...) {
  if (is.function(.subset2(x, "print"))) {
    .subset2(x, "print")(...)
  } else {
    cat(format(x, ...), sep = "\n")
  }

  invisible(x)
}
R/print.R:31

format.R6ClassGenerator untypeabletimeout

unbound variable (line 53)
unbound: object_summaries — one of the package’s own names, itself untyped
error detail
name: object_summaries
gradual mode: timeout
timing: 0.697 s
source
format.R6ClassGenerator <- function(x, ...) {
  classname <- x$classname
  if (is.null(classname)) classname <- "unnamed"
  ret <- paste0("<", classname, "> object generator")

  if (!is.null(x$inherit)) {
    ret <- c(ret, paste0("  Inherits from: <", deparse(x$inherit), ">"))
  }

  ret <- c(ret,
    "  Public:",
    indent(object_summaries(x$public_fields), 4),
    indent(object_summaries(x$public_methods), 4)
  )

  if (!is.null(x$active)) {
    ret <- c(ret,
      "  Active bindings:",
      indent(object_summaries(x$active), 4)
    )
  }

  if (!(is.null(x$private_fields) && is.null(x$private_methods))) {
    ret <- c(ret,
      "  Private:",
      indent(object_summaries(x$private_fields), 4),
      indent(object_summaries(x$private_methods), 4)
    )
  }
  ret <- c(ret, paste("  Parent env:", format(x$parent_env)))
  # R6 generators created by versions <2.1 could be used with this version of
  # print. They had x$lock instead of x$lock_objects, and they didn't have
  # x$lock_class at all. Make sure we don't error in that case. Eventually we'll
  # be able to remove this check.
  if (!is.null(x$lock) && is.logical(x$lock))
    ret <- c(ret, paste("  Locked objects:", x$lock))
  if (!is.null(x$lock_objects))
    ret <- c(ret, paste("  Locked objects:", x$lock_objects))
  if (!is.null(x$lock_class))
    ret <- c(ret, paste("  Locked class:", x$lock_class))
  ret <- c(ret, paste("  Portable:", x$portable))

  paste(ret, collapse = "\n")
}
R/print.R:42

print.R6ClassGenerator typed any: x fuzz ok

((x: any, ...: any) -> null)<>
timing: 0.026 s
fuzzing: 8 inside (8 ok) · 2 outside (2 rejected)
source
print.R6ClassGenerator <- function(x, ...) {
  cat(format(x, ...), sep = "\n")
}
R/print.R:88

plot.R6 typed fuzz ok

∀'a,'b,`a. (((x: { plot: @(...: ('a, empty? | `a)) -> 'b, any }, ...: ('a, `a)) -> 'b)&((x: { plot: ~arrow, any }, ...: ('a, `a)) -> empty))<>
timing: 0.216 s
fuzzing: 24 inside (24 ok) · 8 outside (8 rejected)
type drawn from: (((x: { plot: @(...: ('_ell, empty? | `_ell)) -> 'I2104, any }, ...: ('_ell, `_ell)) -> 'I2104) & ((x: { plot: ~arrow, any }, ...: ('_ell, `_ell)) -> empty))<>
source
plot.R6 <- function(x, ...) {
  if (is.function(x$plot)) {
    x$plot(...)
  } else {
    stop(paste0("No plot method defined for R6 class ", class(x)[1]))
  }
}
R/print.R:146
R/r6_class.R

R6Class untypeable

unbound variable (line 474)
unbound: all_named — a name the prelude does not declare
error detail
name: all_named
timing: 0.446 s
source
R6Class <- encapsulate(function(classname = NULL, public = list(),
                                private = NULL, active = NULL,
                                inherit = NULL, lock_objects = TRUE,
                                class = TRUE, portable = TRUE,
                                lock_class = FALSE, cloneable = TRUE,
                                parent_env = parent.frame()) {

  if (!all_named(public) || !all_named(private) || !all_named(active))
    stop("All elements of public, private, and active must be named.")

  allnames <- c(names(public), names(private), names(active))
  if (any(duplicated(allnames)))
    stop("All items in public, private, and active must have unique names.")

  if ("clone" %in% allnames)
    stop("Cannot add a member with reserved name 'clone'.")

  if (any(c("self", "private", "super") %in%
      c(names(public), names(private), names(active))))
    stop("Items cannot use reserved names 'self', 'private', and 'super'.")

  if ("initialize" %in% c(names(private), names(active)))
    stop("'initialize' is not allowed in private or active.")

  if (length(get_nonfunctions(active)) != 0)
    stop("All items in active must be functions.")

  # Create the generator object, which is an environment
  generator <- new.env(parent = capsule)

  generator$self <- generator

  # Set the generator functions to eval in the generator environment, and copy
  # them into the generator env.
  generator_funs <- assign_func_envs(generator_funs, generator)
  list2env2(generator_funs, generator)

  generator$classname    <- classname
  generator$active       <- active
  generator$portable     <- portable
  generator$cloneable    <- cloneable
  generator$parent_env   <- parent_env
  generator$lock_objects <- lock_objects
  generator$class        <- class
  generator$lock_class   <- lock_class

  # Separate fields from methods
  generator$public_fields   <- get_nonfunctions(public)
  generator$private_fields  <- get_nonfunctions(private)
  generator$public_methods  <- get_functions(public)
  generator$private_methods <- get_functions(private)

  if (cloneable)
    generator$public_methods$clone <- generator_funs$clone_method

  # Capture the unevaluated expression for the superclass; when evaluated in
  # the parent_env, it should return the superclass object.
  generator$inherit <- substitute(inherit)

  # Names of methods for which to enable debugging
  generator$debug_names <- character(0)

  attr(generator, "name") <- paste0(classname, "_generator")
  class(generator) <- "R6ClassGenerator"

  # Print message; in a future version, this will be upgraded to a warning.
  if ("finalize" %in% names(generator$public_methods)) {
    message(
      "R6Class ", classname,
      ": finalize() method is public, but it should be private as of R6 2.4.0. ",
      "This code will continue to work, but in a future version of R6, ",
      "finalize() will be required to be private."
    )
  }

  generator
})
R/r6_class.R:467

.DollarNames.R6 typed any: x accepts outside

((x: any, pattern: vec1) -> CHR<>)<>
timing: 0.074 s
fuzzing: 8 inside (2 ok, 6 error type) · 8 outside (7 rejected, 1 accepted)

Accepted outside the domain x: 1

parameterchangecallreturned
xdrop.DollarNames.R6("pattern" = as.raw(c(0)))(CHR & ~vec1)<> with { }

Other calls inside the domain

callverdicterror
.DollarNames.R6("x" = as.name("x"), "pattern" = complex(real = 0, imaginary = 0))error_typebase::as.environment: invalid object for 'as.environment'
.DollarNames.R6(NULL, 2L)error_typebase::as.environment: using 'as.environment(NULL)' is defunct
.DollarNames.R6(raw(0), "pattern" = as.raw(c(0)))error_typebase::as.environment: invalid object for 'as.environment'
.DollarNames.R6(as.name("x"), NA_complex_)error_typebase::as.environment: invalid object for 'as.environment'
.DollarNames.R6("x" = NULL, "pattern" = "é")error_typebase::as.environment: using 'as.environment(NULL)' is defunct
.DollarNames.R6("x" = function(...) new.env(), "pattern" = as.raw(c(0)))error_typebase::as.environment: invalid object for 'as.environment'
source
.DollarNames.R6 <- function(x, pattern) {
  names <- ls(x, all.names = TRUE)
  names <- names[grepl(pattern, names)]
  setdiff(names, c(".__enclos_env__", "initialize"))
}
R/r6_class.R:546
R/utils.R

<statement> untypeabletyped

unbound variable (line 13)
unbound: duplicated — a name the prelude does not declare
error detail
name: duplicated
gradual mode: typed
timing: 2.83 s
source
encapsulate({
  # Given two named vectors, join them together, and keep only the last element
  # with a given name in the resulting vector. If b has any elements with the
  # same name as elements in a, the element in a is dropped. Also, if there are
  # any duplicated names in a or b, only the last one with that name is kept.
  merge_vectors <- function(a, b) {
    if ((!is.null(a) && length(a) > 1 && is.null(names(a))) ||
        (!is.null(b) && length(b) > 1 && is.null(names(b)))) {
      stop("merge_vectors: vectors must be either NULL or named vectors")
    }

    x <- c(a, b)
    drop_idx <- duplicated(names(x), fromLast = TRUE)
    x[!drop_idx]
  }

  # Check that all elements of a list are named.
  # NULL and empty lists return TRUE.
  all_named <- function(x) {
    if (length(names(x)) != length(x) || any(names(x) == "")) {
      return(FALSE)
    }
    TRUE
  }

  # Return all the functions in a list.
  get_functions <- function(x) {
    funcs <- vapply(x, is.function, logical(1))
    if (all(!funcs)) return(NULL)
    x[funcs]
  }

  # Return all the non-functions in a list.
  get_nonfunctions <- function(x) {
    funcs <- vapply(x, is.function, logical(1))
    if (all(funcs)) return(NULL)
    x[!funcs]
  }
})
R/utils.R:1