diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb
index e4b11b6642cc99ec2683143809bd18de44ec8431..425443778b9bf49fb9f240d968c5147d53b778fc 100644
--- a/Library/Homebrew/formulary.rb
+++ b/Library/Homebrew/formulary.rb
@@ -236,7 +236,7 @@ class Formulary
     spec ||= tab.spec
 
     f = if tap.nil?
-      factory(rack.basename.to_s, spec)
+      factory(keg.rack.basename.to_s, spec)
     else
       begin
         factory("#{tap}/#{keg.rack.basename}", spec)