diff --git a/core/lib/Drupal/Core/Template/TwigExtension.php b/core/lib/Drupal/Core/Template/TwigExtension.php
index 377efe6..9d3ecd3 100644
--- a/core/lib/Drupal/Core/Template/TwigExtension.php
+++ b/core/lib/Drupal/Core/Template/TwigExtension.php
@@ -232,6 +232,7 @@ public function getName() {
    * @see \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute()
    */
   public function getPath($name, $parameters = [], $options = []) {
+    assert('$this->urlGenerator instanceof \Drupal\Core\Routing\UrlGeneratorInterface', 'The URL generator hasn\'t been set up. Any configuration YAML file with a service directive dealing with the Twig configuration can cause this, most likely found in a recently installed or changed module.');
     $options['absolute'] = FALSE;
     return $this->urlGenerator->generateFromRoute($name, $parameters, $options);
   }
@@ -253,6 +254,8 @@ public function getPath($name, $parameters = [], $options = []) {
    * @todo Add an option for scheme-relative URLs.
    */
   public function getUrl($name, $parameters = [], $options = []) {
+    assert('$this->urlGenerator instanceof \Drupal\Core\Routing\UrlGeneratorInterface', 'The URL generator hasn\'t been set up. Any configuration YAML file with a service directive dealing with the Twig configuration can cause this, most likely found in a recently installed or changed module.');
+
     // Generate URL.
     $options['absolute'] = TRUE;
     $generated_url = $this->urlGenerator->generateFromRoute($name, $parameters, $options, TRUE);
@@ -277,6 +280,9 @@ public function getUrl($name, $parameters = [], $options = []) {
    *   A render array representing a link to the given URL.
    */
   public function getLink($text, $url, $attributes = []) {
+    assert('is_string($url) || $url instanceof \Drupal\Core\Url', '$url must be a string or object of type \Drupal\Core\Url');
+    assert('is_array($attributes) || $attributes instanceof \Drupal\Core\Template\Attribute', '$attributes, if set, must be an array or object of type \Drupal\Core\Template\Attribute');
+
     if (!$url instanceof Url) {
       $url = Url::fromUri($url);
     }
@@ -374,6 +380,8 @@ public function isUrlGenerationSafe(\Twig_Node $args_node) {
    *   An asset library.
    */
   public function attachLibrary($library) {
+    assert('is_string($library)', 'Argument must be a string.');
+
     // Use Renderer::render() on a temporary render array to get additional
     // bubbleable metadata on the render stack.
     $template_attached = ['#attached' => ['library' => [$library]]];
@@ -391,8 +399,10 @@ public function attachLibrary($library) {
    * @return string|null
    *   The escaped, rendered output, or NULL if there is no valid output.
    */
-  public function escapePlaceholder($env, $string) {
-    return '<em class="placeholder">' . $this->escapeFilter($env, $string) . '</em>';
+  public function escapePlaceholder(\Twig_Environment $env, $string) {
+    $return = $this->escapeFilter($env, $string);
+
+    return $return ? '<em class="placeholder">' . $return . '</em>' : NULL;
   }
 
   /**
